Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python eps图像中的幻影轴,尽管在matplotlib中设置了不可见轴_Python_Matplotlib_Ghostscript_Eps - Fatal编程技术网

Python eps图像中的幻影轴,尽管在matplotlib中设置了不可见轴

Python eps图像中的幻影轴,尽管在matplotlib中设置了不可见轴,python,matplotlib,ghostscript,eps,Python,Matplotlib,Ghostscript,Eps,我设法把这些行放进我的matplotlib代码中 ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) 希望在保存的图像中隐藏顶部、右侧和左侧轴。它们在png图像中运行良好,但在保存的eps文件中,左侧和顶部仍然存在边界(不确定它们是否为轴)(右轴确实消失) 关于如何在保存为eps图像时隐藏轴/帧边界,有什么想法吗 顺便说一句:

我设法把这些行放进我的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) 关闭XTICK和XTICK标签上的手动设置

然而,以上两个特性是我绝对需要保留在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的屏幕截图

巴布亚新几内亚


作为解决办法,我建议添加以下代码行:

ax.spines['top'].set_color((0,0,0,0))

我基本上是将顶轴设置为透明。

这是由于mpl()中的一个错误,该错误已被修复()


问题是AGG中空画布的默认颜色是(0,0,0,0)(完全透明的黑色),但eps不处理alpha(它只是被删除),所以(0,0,0,0)->(0,0,0)被放入eps文件时。如果禁用轴,则画布的该区域也不会绘制,因此它将保持默认颜色。接受的答案将强制在光栅化过程中渲染这些像素(并将其合成到白色背景上),这样您就不会看到eps文件中的黑线

你能发布上述eps文件的截图吗?@Raiyan done,示例代码,新发现和显示的数字。嘿,我刚刚在我的电脑上运行了你的代码;eps顶部没有那条黑线。@Raiyan这很有趣,你能发布你的python和matplotlib版本吗?那么linux呢?我的版本是matplotlib 1.3.1和python 2.7.5,只需在github/matplotlib上提交一份问题报告即可。祝你好运。很好的调整。我还没有测试,但它应该可以工作。我将再等几天,看看是否有更多的破坏性,而不是伪装。