在.eps文件中将matplotlib等高线标签绘制在AxesSubplot外部

2 投票
1 回答
906 浏览
提问于 2025-04-17 06:37

我正在使用 matplotlib.pyplot(简称 PL)来绘制图表:

FIG = PL.figure(figsize=(12,8), dpi=150)
AX = FIG.add_subplot(111, aspect='equal', xlim=(lonMin,lonMax), ylim=(latMin,latMax))
PL.contourf(lon, lat, swath, range(2,56,1))
PL.colorbar(shrink=0.8, extend='both', ticks=range(5,55,5))
CNTR = PL.contour(lon, lat, rain, colors='black', linewidths=1)
PL.clabel(CNTR, fmt='%2i', inline_spacing=2)
PL.savefig('swaths_ao.png', bbox_inches='tight')
PL.savefig('swaths_ao.eps', bbox_inches='tight')
PL.savefig('swaths_ao.pdf', bbox_inches='tight')
PL.clf()

我遇到的问题是,PL.clabel 在 AX 的边界外也画出了等高线的标签,也就是说,它在图的空白区域也出现了。这种情况只发生在 .eps 文件中,而在 .png 或 .pdf 文件中则没有。巧合的是,我需要的是 .eps 格式。

有没有什么建议可以解决这个问题?

1 个回答

1

听起来像是一个可以在 Github上提交的问题的bug。不过,如果你想找个临时解决办法,假如PDF输出看起来没问题的话,你可以使用pdftops(这个工具是xpdf自带的),然后再用ps2eps

撰写回答