此代码使用matplotlib生成一个boxplot。该图在IPython Notebook中正确显示(参见附图)。但是,savefig
会创建一个空图像。我尝试了文件结尾.png
和.pdf
,但这两种情况都会发生。代码有什么问题?
fig = matplotlib.pyplot.gcf()
GCEMA = (0.26, 0.26, 0.30, 0.51, 0.55, 0.34)
CEM = (0.26, 0.23, 0.30, 0.49, 0.35, 0.24)
selSCAN = (0.19, 0.35, 0.28, 0.45, 0.41, 0.52)
selSCANAD = (0.26, 0.52, 0.37, 0.46, 0.46, 0.47)
N=6
pos = np.arange(N)
ax = plt.axes()
ax.bar(0.6*pos, GCEMA, width = 0.10, color='green', label='GCE-MA')
ax.bar(0.6*pos+0.1, CEM, 0.10, color='blue', label='CE-M')
ax.bar(0.6*pos+0.2, selSCAN, 0.10, color='red', label='selSCAN-ND')
ax.bar(0.6*pos+0.3, selSCANAD, 0.10, color='yellow', label='selSCAN-AD')
ylabel("quality [$\phi$]", fontsize=14)
fig.set_size_inches(5,4)
xticks(rotation=15)
xticks([0.2,0.8,1.4,2,2.6,3.2],['PGP','CAIDA','coPapersDBLP','soc-LiveJournal','uk-2002','eu-2005'])
legend(loc=4, fontsize=10)
show()
savefig("cond.png")
答案 0 :(得分:7)
您可能需要在savefig
之前使用show
。