def simple_plot(figure,X,Y,colors,xlabel="",ylabel="",linked=True,n_points=400,marker_size=10,linewidth=3,alpha=1.0,label=None):
"""
"""
if np.array(colors).ndim == 1:
colors = np.array([colors for i in xrange(len(X))])
#font = fm.FontProperties(family = 'CenturyGothic',fname = '/Library/Fonts/Microsoft/Century Gothic', weight ='light')
font = fm.FontProperties(family = 'Trebuchet', weight ='light')
figure.patch.set_facecolor('white')
axes = figure.add_subplot(111)
if linked:
X_smooth = np.linspace(X.min(),X.max(),n_points)
interpolator = interp1d(X,Y)
Y_smooth = np.array([interpolator(x) for x in X_smooth])
color_interpolator = [interp1d(X,colors[:,k]) for k in [0,1,2]]
colors_smooth = np.transpose([[color_interpolator[k](x) for x in X_smooth] for k in [0,1,2]])
for i in xrange(100):
# color = tuple(color1*(1.0-i/100.0) + color2*(i/100.0))
color = colors_smooth[(i*n_points/100):((i+1)*n_points)/100+1].mean(axis=0)
if i == 0:
axes.plot(X_smooth[(i*n_points/100):((i+1)*n_points)/100+1],Y_smooth[(i*n_points/100):((i+1)*n_points)/100+1],linewidth=linewidth,color=color,alpha=alpha,label=label if marker_size==0 else None)
else:
axes.plot(X_smooth[(i*n_points/100):((i+1)*n_points)/100+1],Y_smooth[(i*n_points/100):((i+1)*n_points)/100+1],linewidth=linewidth,color=color,alpha=alpha)
# axes.plot(X,Y,linewidth=linewidth,color=color,alpha=alpha,label=label)
# ratios = (Y-Y.min())/(Y.max()-Y.min())
axes.scatter(X,Y,c=colors,label=label if marker_size>0 else None,s=marker_size,alpha=alpha,linewidth=linewidth)
# colors =
# for i in xrange(100):
# color = tuple(color1*(1.0-ratios[i]) + color2*ratios[i])
# axes.plot(X_smooth[(i*n_points/100):((i+1)*n_points)/100+1],Y_smooth[(i*n_points/100):((i+1)*n_points)/100+1],linewidth=linewidth,color=color,alpha=1.0)
axes.set_xlabel(xlabel,fontproperties=font, size=10, style='italic')
# axes.set_xlim(X.min(),X.max())
axes.set_xticklabels(axes.get_xticks(),fontproperties=font, size=12)
axes.set_ylabel(ylabel, fontproperties=font, size=10, style='italic')
# axes.set_ylim(Y.min(),Y.max())
axes.set_yticklabels(axes.get_yticks(),fontproperties=font, size=12)
评论列表
文章目录