在Windows中,使用text.usetex时无法将matplotlib图形保存为.eps [英] Can´t save matplotlib figure to .eps in Windows while using text.usetex : True
问题描述
当我运行以下代码时: http://dpaste.com/0210P09 在Linux上一切正常发行版.
When I run the following code: http://dpaste.com/0210P09 everything works fine on my Linux distro.
但是,在Windows7(64位)中,我无法成功将其保存在eps
或svg
中.
However, in Windows7 (64bit) I cannot successfully save it in eps
or svg
.
这是我得到的错误:
Traceback (most recent call last):
File "<ipython-input-1-b8da411d11b0>", line 1, in <module>
runfile('C:/Users/12151056/Documents/Python Scripts/MyPython/1Tplot_2.py', wdir='C:/Users/12151056/Documents/Python Scripts/MyPython')
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 85, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "C:/Users/12151056/Documents/Python Scripts/MyPython/1Tplot_2.py", line 67, in <module>
plt.savefig('excel-6.eps')
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 577, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\figure.py", line 1476, in savefig
self.canvas.print_figure(*args, **kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backend_bases.py", line 2211, in print_figure
**kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backends\backend_ps.py", line 1009, in print_eps
return self._print_ps(outfile, 'eps', *args, **kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backends\backend_ps.py", line 1033, in _print_ps
**kwargs)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backends\backend_ps.py", line 1398, in _print_figure_tex
rotated=psfrag_rotated)
File "C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\backends\backend_ps.py", line 1556, in gs_distill
your image.\nHere is the full report generated by ghostscript:\n\n' + fh.read())
TypeError: Can't convert 'bytes' object to str implicitly
如果我使用text.usetex : False
,我一点问题都没有.
If i use text.usetex : False
I have no problem at all.
我已经安装了livetex full和Ghostscript.
I have livetex full and Ghostscript installed.
有什么建议可以尝试解决吗?
Any suggestions to try and solve it?
推荐答案
这里有两个问题.第一个和次要的是
There are two problems here. The first and minor one is that in
C:\ Users \ 12151056 \ AppData \ Local \ Continuum \ Anaconda3 \ lib \ site-package \ matplotlib \ backends \ backend_ps.py",行1556
C:\Users\12151056\AppData\Local\Continuum\Anaconda3\lib\site-package\matplotlib\backends\backend_ps.py", line 1556
您应该更改
fh.read()
到
fh.read().decode()
这是一个Python 2/3错误,发生在处理Ghostscript出错的事实时.
This is a Python 2/3 bug, that occurs while handling the fact that something with Ghostscript went wrong.
主要问题是matplotlib找不到Ghostscript,因为它不在路径环境变量中.您可以通过打开命令提示符并尝试使用命令gswin32c
或gs
进行检查.如果找不到这些命令,则必须将这些Ghostscript可执行文件的路径添加到path环境变量中.在我的情况下是:
The main problem is that matplotlib cannot find Ghostscript because it is not in the path environmental variable. You can check that by opening a command prompt and trying the command gswin32c
or gs
. If these commands are not found you have to add the path of these Ghostscript executables to the path environmental variable. In my case it was:
C:\ Program Files(x86)\ gs \ gs8.54 \ bin
C:\Program Files (x86)\gs\gs8.54\bin
但这取决于您的安装路径.
but it depends on your installation path.
这篇关于在Windows中,使用text.usetex时无法将matplotlib图形保存为.eps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!