如何使matplotlib svg以查看器安全的方式导出边界框

2024-04-26 10:39:32 发布

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

每当我进行svg导出并且在前面使用了set\uxlim或set\ylim时,完整的曲线就会在svg中可见(下面右侧的输出)。至少,只要我用ubuntu图像查看器打开文件,就会发生这种情况。例如,Inkscape可以很好地打开svg。不幸的是,我不知道什么应用程序的人,我发送的数字将用于开幕式。有没有什么方法可以抑制这种行为,并“削减”任何观众的边界框曲线?你知道吗

import numpy as np
import matplotlib.pyplot as plt

plt.ion()
plt.plot(np.random.random_integers(0,100, size= 50))
plt.gca().set_ylim((10,50))

plt.gcf().savefig('test_pdf.pdf')
plt.gcf().savefig('test_svg.svg')

enter image description here


Tags: svgtestimportpdfubuntuasnpplt