1

此代码使用 matplotlib 生成箱线图。该图在 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")

在此处输入图像描述

4

1 回答 1

7

你可能需要使用savefigbefore show

于 2013-09-27T09:13:53.250 回答