无法将图形另存为 .eps [无法识别 gswin32c] [英] Can't save figure as .eps [gswin32c is not recognized]

查看:82
本文介绍了无法将图形另存为 .eps [无法识别 gswin32c]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 PyLab(64 位)的 Enthought Canopy.对于我的报告,我需要使用Latex(XeLaTex),并且使用matplotlib完成绘制.

I'm using Enthought Canopy with PyLab(64-bit). For my report I need to use Latex (XeLaTex) and the plots are done with matplotlib.

要有第一个想法,我只是从 http://matplotlib.org/users/复制了第二个示例usetex.html 并对其进行编译.它看起来不错,我可以毫无问题地将其保存为普通的 png.但是,如果我尝试将其另存为.eps或.ps,它将无法正常工作,并出现错误:

To have an first idea I just copied the second example from http://matplotlib.org/users/usetex.html and compiled it. It looks fine and I can save it as a normal png without problems. However if i try to save it as .eps or.ps it does not work and an error appears:

以10为底的int()无效文字:"

invalid literal for int() with base 10: "

另外在 Pylab shell 中它显示:

Additionaly in the Pylab shell it shows:

"gswin32c"未被识别为内部或外部命令,可操作程序或批处理文件.

'gswin32c' is not recognized as an internal or external command, operable program or batch file'.

如果我将其另存为.pdf,则没有任何问题,只是文本全是黑色,而不是红色和蓝色.这是一个问题,因为在我的绘图中,我有两个轴,我需要对它们进行着色以提高可读性.

If I save it as .pdf I have no problems except the text is all black instead of being red and blue. This is a problem because in my plots I have two axes and I need them colorized for better readability.

如果我然后尝试从给定的示例(所有文本)中删除一些行,我仍然无法将其保存为 .eps 或 .ps.我无法弄清楚问题所在,与此相关的所有其他主题都没有让我深入了解.所以我真的需要你的帮助,因为我的报告不能使用 .png.

If I then try to delete some lines from the example given (all text) I still cannot save it as .eps nor .ps. I can't figure out the problem and all the other topics related to this have not given me an insight. So I really need your help because I can't use .png for my report.

先谢谢你!!!

推荐答案

我终于设法解决了这个问题.它可能看起来很奇怪,但也许其他人可以从中受益.

I finally managed to solve this problem. It might look weird but maybe other people can benefit from it.

解决方案可能取决于您使用的软件.我在W8 64位下使用Enthought Canopy(Python)和MikTeX 2.9.如果您想使用 'text.usetex': True 选项使用 matplotlib 输出 .ps 和 .eps 文件,那么您将遇到上面发布的问题.

The solution might depend upon the software you use. I use Enthought Canopy (Python) and MikTeX 2.9 under W8 64bit. If you want to output .ps and .eps files with matplotlib using the 'text.usetex': True option then you will encounter the problem posted above.

解决方案:

  1. http://www.ghostscript.com/download/下载并安装Ghostscript(32位)gsdnld.html.
  2. http://www.tm.uka.de/下载 ps2eps-1.68.zip〜bless/ps2eps .手册中给出了程序,但是我想指出环境变量的部分.在这最后一步中,您需要转到控制面板 --> 系统 --> 高级系统设置.然后单击标题高级",在窗口底部您会看到单击环境变量".然后您使用新建"按钮作为 USERNAME 的用户变量.然后输入变量名ps2eps",输入保存 ps2eps.pl 文件的实际路径作为变量值.就我而言,这是C:\Program Files (x86)\ps2eps\bin\".您可以检查是否在命令窗口中输入了ps2eps".
  3. http://www.foolabs.com/xpdf下载xpdfbin-win-3.03.zip/download.html.您只需要文件pdftops.exe".但是,我无法像在步骤 2 中那样分配路径.我通过将pdftops.exe"放在 MikTeX 2.9 文件夹中解决了这个问题.对我来说确切的位置是'C:\ Program Files \ MiKTeX 2.9 \ miktex \ bin \ x64'.
  1. Download and install Ghostscript (32bit) from http://www.ghostscript.com/download/gsdnld.html.
  2. Download ps2eps-1.68.zip from http://www.tm.uka.de/~bless/ps2eps. The proceeding is given in the manual, however I like to point out the part with the environment variables. In this last step you need to go to Control Panel --> System --> Advanced system settings. Then click on the header 'Advanced' and on the bottom of the window you see 'Environment Variables' on which you click. Then you use the 'New'-Button for User Variables for USERNAME. Then you type in as variable name 'ps2eps' and for variable value you type in the actual path where you have saved the ps2eps.pl file. In my case this is 'C:\Program Files (x86)\ps2eps\bin\'. You can check if you type 'ps2eps' in the command-window.
  3. Download xpdfbin-win-3.03.zip from http://www.foolabs.com/xpdf/download.html. You only need the file 'pdftops.exe'. However I could not assign a path like in step 2. I solved this by putting the 'pdftops.exe' in the MikTeX 2.9 folder. The exact location for me was 'C:\Program Files\MiKTeX 2.9\miktex\bin\x64'.

然后我能够将数字保存为 .ps 并且不再有任何错误消息.请记住使用在 http://matplotlib.org/users/usetex.html 下建议的设置后记选项".在我自己使用了以下设置:

I was then able to save figures as .ps and have no more any error messages. Remember to use the settings proposed on http://matplotlib.org/users/usetex.html under 'postscript options'. In myself used the following settings:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.rc('font', **{'family':'serif', 'serif':['Computer Modern Roman'],
              'monospace':['Computer Modern Typewriter']})
params = {'backend': 'ps',
      'text.latex.preamble': [r"\usepackage{upgreek}",
                              r"\usepackage{siunitx}",
                              r"\usepackage{amsmath}",
                              r"\usepackage{amstext}",],
      'axes.labelsize': 18,
      #'axes.linewidth': 1,
      #'text.fontsize':17,
      'legend.fontsize': 10,
      'xtick.labelsize': 13,
      #'xtick.major.width' : 0.75,
      'ytick.labelsize': 13,
      'figure.figsize': [8.8,6.8],
      #'figure.dpi': 120,
      'text.usetex': True,
      'axes.unicode_minus': True,
      'ps.usedistiller' : 'xpdf'}          
mpl.rcParams.update(params)
mpl.rcParams.update({'figure.autolayout':True})

(而在后面的情节中,许多参数只是为了我自己的目的)

(whereas many of the params are just for my own purpose later in the plots)

作为初学者,如果您从 Python 控制台运行脚本,我不太了解所使用的后端"的依赖性.但是,我以前没有使用任何--pylab设置就使用了它,而且我不知道如果他已经在具有特定matplotlib后端的控制台中工作了,是否需要手动切换后端.

As a beginner I am not well informed about the dependence from the 'backend' used if you are running a script from your python console. I however used this without any --pylab settings in before and I do not know if one needs to switch the backend manually if he is working already in a console with a specific matplotlib backend.

这篇关于无法将图形另存为 .eps [无法识别 gswin32c]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆