从图形上删除轴

Ivo*_*cky 2 python axes matplotlib figure

是否可以从轴上拆下轴pyplot.figure()

使用pyplot.imsave()来创建没有轴的图像就可以了

plt.imsave(file, zi)
Run Code Online (Sandbox Code Playgroud)

图像使用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)
Run Code Online (Sandbox Code Playgroud)

图像使用pyplot.savefix()生成

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

Ivo*_*cky 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)
Run Code Online (Sandbox Code Playgroud)