Matplotlib: PDF figures hatching resolution problems

2024-10-05 14:32:38 发布

您现在位置:Python中文网/ 问答频道 /正文

当使用Matplotlib生成带有图案填充的图形(例如饼图、条形图、气泡图)时,我很难从PDF版本的图形中获得像样的分辨率。保存为EPS是可以的,但是只要我使用epstopdf或MPL的savefig(*.pdf),图案填充就会变得像素化和离散化。。。图像的矢量特性似乎已经丢失。在

请参阅下面的最小代码。在

from matplotlib import pyplot as plt

# Define hatching styles
hatching = ["/", "o"]

fig, ax = plt.subplots()
wedges, texts = ax.pie([0.4, 0.6], colors=("SteelBlue", "Tomato"))

# Apply the hatching
for j, patch in enumerate(wedges): patch.set_hatch(hatching[j])

fig.savefig("hatchtest.pdf")

我用Gimp放大了一部分情节来说明区别。。。在

放大EPS图Generated with EPS terminal

放大PDF图Generated with PDF terminal

至于具体的系统细节,我使用的是Ubuntu13.04、Python2.7.4和MPL1.2.1。我尝试过不同的后端,但似乎没有解决这个问题。我最理想的是在EPS和PDF中有很好的矢量图像,这样它对日志都很友好。任何建议都将不胜感激。在


Tags: 图像图形pdfmatplotlib矢量figplteps