当我尝试将python图像保存为PostScript时,使用Latex和xfrac包时,我收到错误,我可以将图形保存为其他格式,但不能保存在PostScript中
这是我使用的代码..
import matplotlib
import matplotlib.pyplot as plt
# Use LaTeX for rendering
matplotlib.rcParams["text.usetex"] = True
# load the xfrac package
matplotlib.rcParams["text.latex.preamble"].append(r'\usepackage{xfrac}')
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([0,1],[1,0])
ax.text(.5, .5, r'$\sfrac{1}{2}$')
plt.savefig('111.ps')
这是我得到的错误(如果我不使用xfrac包我没有收到错误)
LaTeX was not able to process your file:
Here is the full report generated by LaTeX:
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=latex)
restricted \write18 enabled.
entering extended mode
(/tmp/tmp0Nr4Ze.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 79 languages loaded.
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/base/size10.clo))
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/type1cm/type1cm.sty)
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/psnfss/helvet.sty
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/graphics/keyval.sty)
) (/home/users/MyName/Local/Latex/texmf-dist/tex/latex/psnfss/courier.sty
) (/home/users/MyName/Local/Latex/texmf-dist/tex/latex/base/textcomp.sty
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/base/ts1enc.def))
(/home/users/MyName/texmf/tex/latex/xfrac.sty
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/amsmath/amstext.sty
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/graphics/graphicx.st
y
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/graphics/graphics.st
y (/home/users/MyName/Local/Latex/texmf-dist/tex/latex/graphics/trig.sty)
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/latexconfig/graphics
.cfg)
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/graphics/dvips.def))
) (/home/users/MyName/texmf/tex/latex/l3keys2e.sty
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/l3kernel/expl3.sty
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/l3kernel/expl3-code.
tex
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/etex-pkg/etex.sty))
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/l3kernel/l3unicode-d
ata.def)
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/l3kernel/l3dvips.def
))) (/home/users/MyName/texmf/tex/latex/xparse.sty)
(/home/users/MyName/texmf/tex/latex/xtemplate.sty))
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/geometry/geometry.st
y
(/home/users/MyName/Local/Latex/texmf-dist/tex/generic/oberdiek/ifpdf.sty
)
(/home/users/MyName/Local/Latex/texmf-dist/tex/generic/oberdiek/ifvtex.st
y)
(/home/users/MyName/Local/Latex/texmf-dist/tex/generic/ifxetex/ifxetex.st
y)
Package geometry Warning: Over-specification in `h'-direction.
`width' (614.295pt) is ignored.
Package geometry Warning: Over-specification in `v'-direction.
`height' (794.96999pt) is ignored.
) (/home/users/MyName/Local/Latex/texmf-dist/tex/latex/psfrag/psfrag.sty)
! LaTeX Error: Option clash for package graphicx.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.13 \usepackage
{color}
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/graphics/color.sty
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/latexconfig/color.cf
g)
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/graphics/dvipsnam.de
f))
No file tmp0Nr4Ze.aux.
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/base/ts1cmr.fd)
(/home/users/MyName/Local/Latex/texmf-dist/tex/latex/psnfss/ot1pnc.fd)
*geometry* detected driver: dvips
<tmp0Nr4Ze.eps> [1] (./tmp0Nr4Ze.aux) )
(see the transcript file for additional information)
Output written on tmp0Nr4Ze.dvi (1 page, 3368 bytes).
Transcript written on tmp0Nr4Ze.log.
任何人都知道如何解决这个问题?
修改
我现在发现如果我尝试将其保存为pgf(LaTeX PGF图)
我收到此错误
Error processing '\(\displaystyle \sfrac{\tau_{peel}}{\tau_{m}}\)'
LaTeX Output:
! Undefined control sequence.
<argument> ...}\selectfont \(\displaystyle \sfrac
{\tau _{peel}}{\tau _{m}}\)
<*> ...splaystyle \sfrac{\tau_{peel}}{\tau_{m}}\)}
No pages of output.
Transcript written on texput.log.
EDIT2:
我有时会遇到这个错误
dvipng warning: No image output from inclusion of raw PostScript GPL Ghostscript 9.05: Unrecoverable error, exit code 1
所以我更新了Ghostscript,现在我收到了这个错误: - )
dvipng warning: No image output from inclusion of raw PostScript GPL Ghostscript 9.14: Unrecoverable error, exit code 1
答案 0 :(得分:2)
在这种情况下,为了输出ps
- 您需要将dvips
选项传递给graphicx
:
\usepackage[dvips]{graphicx}
脚本应为:
import matplotlib
import matplotlib.pyplot as plt
# Use LaTeX for rendering
matplotlib.rcParams["text.usetex"] = True
# load the xfrac package
matplotlib.rcParams["text.latex.preamble"].append(r'\usepackage[dvips]{graphicx}\usepackage{xfrac}')
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([0,1],[1,0])
ax.text(.5, .5, r'$\sfrac{1}{2}$')
plt.savefig('111.ps')
matplotlib可能会加载graphicx
,为了输出ps
matplotlib使用dvips
驱动程序,因此必须将选项传递给graphicx
我认为虽然使用原始代码输出pdf
并使用ps
将其转换为ghostscript
更容易。