已经设置为不可见轴,我设法把这些线在我的matplotlib代码幻象轴尽管matplotlib
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
在保存的图像隐藏顶部,右侧的希望,左轴。他们在PNG图像上工作得很好,但在保存的eps文件中,左侧和顶部(右侧轴确实消失)仍然存在边界(不确定它们是否是轴)。
有关如何在保存为EPS图像时如何隐藏轴/边框边界的任何想法?
BTW:我不想
ax.axis('off')
,因为我确实需要中轴下方工作。
EDIT
我只是做了多次试验用下面的最小工作示例中,原来的轴将是不可见的,即使在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
@Raiyan完成,示例代码,新发现,以及显示的数字。 – nye17
嘿,我只是在我的电脑上运行你的代码;该eps顶部没有黑线。 – Raiyan