gpt4 book ai didi

python - matplotlib 运行时错误 : In select_charmap: Could not set the charmap using latex

转载 作者:太空宇宙 更新时间:2023-11-04 03:18:50 24 4
gpt4 key购买 nike

我尝试运行以下 python 代码(安装了 Python 3.4.7 + scipy;安装了 MikTeX 2.9.4476;Windows 7)

from matplotlib import pyplot as plt
from matplotlib.pyplot import rc

rc('text', usetex=True)

# plotting
data = range(100)
plt.plot(data, data, label='0.3 m')

plt.legend()
plt.savefig("test.png")
plt.savefig("test.svg")
# plt.show()

如果我使用 plt.savefig("test.svg") 或任何其他矢量图形格式,则会出现以下错误。没有这个保存命令一切正常。打印错误:

Traceback (most recent call last):
File "U:\ICCAP\S_SVN\ETHAN\test.py", line 12, in <module>
plt.savefig("test.svg")
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\pyplot.py", line 688, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\figure.py", line 1539, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backend_bases.py", line 2230, in print_figure
**kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backends\backend_svg.py", line 1206, in print_svg
return self._print_svg(filename, svgwriter, fh_to_close, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backends\backend_svg.py", line 1234, in _print_svg
self.figure.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\figure.py", line 1133, in draw
func(*args)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\axes\_base.py", line 2304, in draw
a.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\legend.py", line 482, in draw
self._legend_box.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 286, in draw
c.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 286, in draw
c.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 286, in draw
c.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 286, in draw
c.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\offsetbox.py", line 867, in draw
self._text.draw(renderer)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\text.py", line 792, in draw
mtext=mtext)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backends\backend_svg.py", line 1152, in draw_tex
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\backends\backend_svg.py", line 957, in _draw_text_as_path
return_new_glyphs_only=True)
File "C:\WinPython-32bit-3.4.3.7Qt5\python-3.4.3\lib\site-packages\matplotlib\textpath.py", line 346, in get_glyphs_tex
font.select_charmap(charmap_code)
RuntimeError: In select_charmap: Could not set the charmap

有什么问题/可以改进的想法吗?

最佳答案

我也有同样的问题,我通过将 matplotlib 升级到 1.5.1 来修复它。这似乎与 Matplotlib 试图渲染一些字体而没有捕捉到应该被捕捉到的异常有关。

相关:https://github.com/matplotlib/matplotlib/pull/5770#issuecomment-168212746

关于python - matplotlib 运行时错误 : In select_charmap: Could not set the charmap using latex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35342739/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com