liyang005

python voronoi_plot_2d 如何set xlim, ylim,问题未解决

def plotkmeans(x, y, oc,centers0, subplot, title, ayc):
     ...:     plt.subplot(subplot)
     ...: #def plotkmeans(x, y, oc, centers0, title, ayc):
     ...: #    fig,ax = plt.figure(12,6)
     ...:     #ayc= ['yello','purple','blue','black','red','magenta']
     ...:     yc = []
     ...:     if np.max(y) <len(ayc):
     ...:         for i in y:
     ...:             yc.append(ayc[i])
     ...:     else:
     ...:         print('cluster number larger than the color array')
     ...:         yc= y
     ...:     yc = np.array(yc)
     ...:     points =  centers0
     ...:     from scipy.spatial import Voronoi, voronoi_plot_2d
     ...:     vor = Voronoi(points)
     ...: 
     ...:     #voronoi_plot_2d(vor,ax=ax,show_vertices=False,line_colors='orange',
     ...:     #                  line_width=2, line_alpha=0.6, point_size=2)
     ...: 
     ...:     plt.scatter(x[:,0],x[:,1],c=yc)
     ...:     #yc=[i for i in range(np.max(y)+1)]
     ...:     plt.scatter(oc[:,0],oc[:,1],c='green',s=100,marker='*')
     ...:     plt.scatter(centers0[:,0],centers0[:,1],c='red',s=100,marker='x')
     ...:     #plt.scatter(oc[:,0],oc[:,1],c='green',s=100,marker='*')
     ...:     plt.xlabel('属性1',font=zhfont1,fontsize=15)
     ...:     plt.ylabel('属性2',font=zhfont1,fontsize=15)
     ...:     plt.title(title,font=zhfont1,fontsize=16)     ...:    

              voronoi_plot_2d(vor, ax=fig.gca(), show_vertices=False, line_colors='orange',
     ...:                  line_width=2, line_alpha=0.6, point_size=2)

#问题:voronoi_plot_2d的范围没有被限制在前面plt的范围,最后用plt.show()显示的图中,x,ylim都是voronoi_plot_2d的范围,这导致前面plt的数据没有反映全


评论