【发布时间】:2013-11-04 03:46:19
【问题描述】:
我设法将这些行放在我的 matplotlib 代码中
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
希望在保存的图像中隐藏顶部、右侧和左侧轴。他们在png图像中工作正常,但是在保存的eps文件中,左侧和顶部(右侧轴确实消失了)仍然存在边界(不确定它们是否是轴)。
关于保存为 eps 图像时如何隐藏轴/帧边界的任何想法?
顺便说一句:我不想要
ax.axis('off')
因为我确实需要底轴才能工作。
编辑
我刚刚使用以下最小工作示例进行了几次测试,结果证明,即使在 eps 输出中,如果我要么 1) 关闭 eps 中的光栅化; 或者 2) 关闭 xticks 和 xticklabels 的手动设置
但是,以上两个功能都是我绝对需要保留在 eps 输出中的,那么,有什么解决方案吗?
import matplotlib.pyplot as plt
import numpy as np
# setting up fig and ax
fig = plt.figure(figsize=(12,6))
ax = fig.add_axes([0.00,0.10,0.90,0.90])
# translucent vertical band as the only subject in the figure
# note the zorder argument used here
ax.axvspan(2014.8, 2017.8, color="DarkGoldenRod", alpha=0.3, zorder=-1)
# setting up axes
ax.set_xlim(2008, 2030)
ax.set_ylim(-2, 2)
# if you toggle this to False, the axes are hidden
if True :
# manually setting ticks
ticks = np.arange(2008, 2030, 2)
ax.set_xticks(ticks)
ax.set_xticklabels([r"$\mathrm{" + str(r) + r"}$" for r in ticks], fontsize=26, rotation=30)
ax.get_xaxis().tick_bottom()
ax.set_yticks([])
# hide all except for the bottom axes
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
# if you toggle this to False, the axes are hidden
if True :
# this is to make sure the rasterization works.
ax.set_rasterization_zorder(0)
# save into eps and png separately
fig.savefig("test.eps", papertype="a4", format="eps", bbox_inches='tight', pad_inches=0.1, dpi=None)
fig.savefig("test.png", papertype="a4", format="png", bbox_inches='tight', pad_inches=0.1, dpi=None)
和eps的截图
对于png
【问题讨论】:
-
你能把上述eps文件的截图贴出来吗?
-
@Raiyan 完成,示例代码、新发现和图表显示。
-
嘿,我刚刚在我的电脑上运行了你的代码; eps 顶部没有那条黑线。
-
@Raiyan 现在很有趣,你能发布你的 python 和 matplotlib 版本吗?和Linux?我的是 matplotlib 1.3.1 和 python 2.7.5
-
只需在 github/matplotlib 上提交问题报告。手指交叉。 github.com/matplotlib/matplotlib/issues/2580
标签: python matplotlib ghostscript eps