从图中移除轴

时间:2011-07-05 17:11:44

标签: python matplotlib figure axes

是否可以从pyplot.figure()

中删除轴

使用pyplot.imsave()创建没有轴的图像可以正常工作

plt.imsave(file, zi)

Image produces with pyplot.imsave()

但它有限,因为它只适用于网格数据。

当我使用pyplot.figure()并使用pyplot.savefig()保存时,如下所示

...
# create figure
fig = plt.figure(figsize=(1.0,1.0))
# apply contour plot
plt.contour(zi,15,linewidths=0.1,colors='k')
plt.contourf(zi,15,cmap=plt.cm.jet)
# flip the y-axis
ax = plt.gca()
ax.set_ylim(ax.get_ylim()[::-1])
# save to file, 256x256 pixels
plt.savefig(file1, dpi=256)

Image produces with pyplot.savefix()

保存的图像保持其轴,如上图所示。

1 个答案:

答案 0 :(得分:5)

我能够使用以下代码删除轴显示和分配给轴的任何间距:

fig = plt.figure(figsize=(1.0,1.0))
ax = fig.add_axes([0.0, -0.2, 1.2, 1.2])
plt.contour(zi,15,linewidths=0.1,colors='k')
plt.contourf(zi,15,cmap=plt.cm.jet)
ax.set_ylim(ax.get_ylim()[::-1])
ax.set_axis_off()
plt.savefig(file1, dpi=256)