简体   繁体   English

使用MatPlotlib和LaTex文本渲染(usetex)创建.eps输出时出错

[英]Error creating .eps output with matplotlib with LaTex text rendering (usetex)

I was trying to create .eps output with Latex text rendering using the example provided by the matplotlib homepage . 我试图使用matplotlib主页提供的示例使用Latex文本渲染创建.eps输出。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This demo is tex_demo.py modified to have unicode. See that file for
more information.
"""
from __future__ import unicode_literals
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['text.usetex']=True
mpl.rcParams['text.latex.unicode']=True
from numpy import arange, cos, pi
from matplotlib.pyplot import (figure, axes, plot, xlabel, ylabel, title,
     grid, savefig, show)

figure(1, figsize=(6,4))
ax = axes([0.1, 0.1, 0.8, 0.7])
t = arange(0.0, 1.0+0.01, 0.01)
s = cos(2*2*pi*t)+2
plot(t, s)

xlabel(r'\textbf{time (s)}')
ylabel(r'\textit{Velocity (\u00B0/sec)}', fontsize=16)
title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
      fontsize=16, color='r')
grid(True)
savefig('tex_demo.eps')

Where I just added the " savefig('tex_demo.eps') " command at the end. 我刚刚在最后添加“ savefig('tex_demo.eps') ”命令的地方。 However, I get the error message: 但是,我收到错误消息:

File "", line 1, in 文件“”,第1行,位于
runfile('E:/Software/Python/Test/Plot/Matplotlib/tex_unicode_demo.py', wdir='E:/Software/Python/Test/Plot/Matplotlib') 运行文件('E:/Software/Python/Test/Plot/Matplotlib/tex_unicode_demo.py',wdir ='E:/ Software / Python / Test / Plot / Matplotlib')

File "C:\\Python27\\lib\\site-packages\\spyderlib\\widgets\\externalshell\\sitecustomize.py", line 540, in runfile execfile(filename, namespace) 运行文件execfile中的文件“ C:\\ Python27 \\ lib \\ site-packages \\ spyderlib \\ widgets \\ externalshell \\ sitecustomize.py”,行540(文件名,名称空间)

File "E:/Software/Python/Test/Plot/Matplotlib/tex_unicode_demo.py", line 27, in savefig('tex_demo.eps',format='eps') 在savefig('tex_demo.eps',format ='eps')中的文件“ E:/Software/Python/Test/Plot/Matplotlib/tex_unicode_demo.py”,第27行

File "C:\\Python27\\lib\\site-packages\\matplotlib\\pyplot.py", line 577, in savefig res = fig.savefig(*args, **kwargs) 在savefig res = fig.savefig(* args,** kwargs)中的文件“ C:\\ Python27 \\ lib \\ site-packages \\ matplotlib \\ pyplot.py”,第577行

File "C:\\Python27\\lib\\site-packages\\matplotlib\\figure.py", line 1470, in savefig self.canvas.print_figure(*args, **kwargs) 在savefig self.canvas.print_figure(* args,** kwargs)中的文件“ C:\\ Python27 \\ lib \\ site-packages \\ matplotlib \\ figure.py”,行1470

File "C:\\Python27\\lib\\site-packages\\matplotlib\\backends\\backend_qt5agg.py", line 161, in print_figure FigureCanvasAgg.print_figure(self, *args, **kwargs) 文件“ C:\\ Python27 \\ lib \\ site-packages \\ matplotlib \\ backends \\ backend_qt5agg.py”,行161,在print_figure FigureCanvasAgg.print_figure(self,* args,** kwargs)中

File "C:\\Python27\\lib\\site-packages\\matplotlib\\backend_bases.py", line 2194, in print_figure **kwargs) 文件“ C:\\ Python27 \\ lib \\ site-packages \\ matplotlib \\ backend_bases.py”,行2194,在print_figure ** kwargs中)

File "C:\\Python27\\lib\\site-packages\\matplotlib\\backends\\backend_ps.py", line 992, in print_eps return self._print_ps(outfile, 'eps', *args, **kwargs) 文件“ C:\\ Python27 \\ lib \\ site-packages \\ matplotlib \\ backends \\ backend_ps.py”,行992,在print_eps中返回self._print_ps(outfile,'eps',* args,** kwargs)

File "C:\\Python27\\lib\\site-packages\\matplotlib\\backends\\backend_ps.py", line 1016, in _print_ps **kwargs) 文件“ C:\\ Python27 \\ lib \\ site-packages \\ matplotlib \\ backends \\ backend_ps.py”,行1016,在_print_ps ** kwargs中)

File "C:\\Python27\\lib\\site-packages\\matplotlib\\backends\\backend_ps.py", line 1381, in _print_figure_tex rotated=psfrag_rotated) 文件“ C:\\ Python27 \\ lib \\ site-packages \\ matplotlib \\ backends \\ backend_ps.py”,行1381,在_print_figure_tex旋转= psfrag_rotated中)

File "C:\\Python27\\lib\\site-packages\\matplotlib\\backends\\backend_ps.py", line 1539, in gs_distill your image.\\nHere is the full report generated by ghostscript:\\n\\n' + fh.read()) 在gs_still中,将文件“ C:\\ Python27 \\ lib \\ site-packages \\ matplotlib \\ backends \\ backend_ps.py”行1539提取到图像中。\\ n以下是ghostscript生成的完整报告:\\ n \\ n'+ fh.read( ))

RuntimeError: ghostscript was not able to process your image. RuntimeError:ghostscript无法处理您的图像。 Here is the full report generated by ghostscript: 这是ghostscript生成的完整报告:

I already made sure that the pathes to the executeables of LaTeX, dvipng and Ghostscript are in my path variable. 我已经确保LaTeX,dvipng和Ghostscript的可执行文件的路径在我的path变量中。

Matplotlib: 1.4.2 Matplotlib:1.4.2

Ghostscript: 9.15 脚本:9.15

Python: 2.7.6 的Python:2.7.6

OS: Windows 8.1 作业系统:Windows 8.1

I haven't managed to directly solve your problem. 我没有设法直接解决您的问题。 However I have found a work around. 但是我找到了解决方法。 I have an install of Cygwin on my windows PC. 我在Windows PC上安装了Cygwin Before I call my python script I added the Cygwin bin directory into my windows path: 在调用python脚本之前,我将Cygwin bin目录添加到了Windows路径中:

set "PATH=%PATH%;C:\cygwin64\bin"

For me at least this solved my problem. 对我来说,至少这解决了我的问题。 Hope it is of help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM