我正在使用matplotlib.pyplot创建一个条形图并将图像保存在同一个文件中但在不同的函数中。但问题是,在绘制/保存我的图像时,它也会添加条形图。
Sample Code:
THIS FUNCTION CREATES BAR GRAPH
def plotbargraph(file1_class,file2_class,label_list,color_list, flag , title,classname,filename):
# SOME CODE
for i in range(2):
print '********'
plt.bar(index+bar_width[i],c[i], bar_width[i+1],alpha=opacity,color=color_list[i],label=label_list[i])
plt.xlabel('Classes')
plt.ylabel('Pixels Count')
plt.title(title)
plt.xticks(index + bar_width[1],classname)
plt.legend()
plt.tight_layout()
plt.savefig(path+filename+'.png')
#THIS FUNCTION CREATES IMAGE
def plotimage(image,labels,classname):#input - array of labels and image of 1..n classes
cmap = mpl.colors.ListedColormap(['r', 'g', 'b','k'])
img = plt.imshow(image, cmap=cmap , vmin = 1, vmax =5)
plt.imsave(path+classname+'.png',image,cmap=cmap)
plt.savefig(path+classname+'_legend'+'.png')
#plt.show()
#BAR GARAPH CALLED
plotbargraph()
def createdifferencemap(file2_read,unique_val2,true_x_axis,true_y_axis,x_axis,y_axis,class_name):
for i in range(unique_val2.shape[0]):
3 PLOT IMAGE CALLED
plotimage(c,labels,class_name[i])
# CREATE DIFFERENCE MAP CALLED
createdifferencemap()