2014-04-27 51 views
3

在運行下面的代碼:找不到字體時使用matplotlib AGG的後端與usetex導出PDF =真

import matplotlib as mpl 
import pylab 

mpl.use('agg') 
mpl.rcParams['text.usetex']=True 

pylab.plot(range(5)) 
pylab.savefig("test.pdf") 

產生一個錯誤:

Traceback (most recent call last): 
    File "bug_test.py", line 12, in <module> 
    pylab.savefig("test.pdf") 
    File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 561, in savefig 
    return fig.savefig(*args, **kwargs) 
    File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1421, in savefig 
    self.canvas.print_figure(*args, **kwargs) 
    File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 2220, in print_figure 
    **kwargs) 
    File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1952, in print_pdf 
    return pdf.print_pdf(*args, **kwargs) 
    File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 2358, in print_pdf 
    file.close() 
    File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 507, in close 
    self.writeFonts() 
    File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 604, in writeFonts 
    realpath, stat_key = get_realpath_and_stat(filename) 
    File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 982, in __call__ 
    stat = os.stat(realpath) 
OSError: [Errno 2] No such file or directory: '<current directury>/cmr17' 

字體cmr17做存在於標準乳膠分佈。 (mf,afm和tfm)文件。導出到postscript或EPS完美工作。但我想要一個PDF輸出作爲圖像導入到XeTeX文檔。刪除usetex = True部分運行正常。但我希望我的字體與我的LaTeX文檔相對應。

什麼可能是錯誤的?

(Debian的不穩定,matplotlib 1.3.1,蟒蛇2.7的texlive 2013.20140408-​​1)

感謝, 羅南

編輯:用 '--verbose調試'

$HOME=/home/ronen 
matplotlib data path /usr/share/matplotlib/mpl-data 
loaded rc file /home/ronen/.config/matplotlib/matplotlibrc 
matplotlib version 1.3.1 
verbose.level debug 
interactive is True 
platform is linux2 
loaded modules: <dictionary-keyiterator object at 0x7fa39e47d890> 
CACHEDIR=/home/ronen/.cache/matplotlib 
Using fontManager instance from /home/ronen/.cache/matplotlib/fontList.cache 
backend agg version v2.2 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
find_tex_file(pcrr7t.tfm): ['kpsewhich', u'pcrr7t.tfm'] 
find_tex_file result: /usr/share/texlive/texmf-dist/fonts/tfm/adobe/courier/pcrr7t.tfm 
opening tfm file /usr/share/texlive/texmf-dist/fonts/tfm/adobe/courier/pcrr7t.tfm 
lh=18, bc=0, ec=170, nw=3, nh=16, nd=16 
find_tex_file(pcrr7t.vf): ['kpsewhich', u'pcrr7t.vf'] 
find_tex_file result: /usr/share/texlive/texmf-dist/fonts/vf/adobe/courier/pcrr7t.vf 
Dvi: /usr/share/texlive/texmf-dist/fonts/vf/adobe/courier/pcrr7t.vf 
find_tex_file(pcrr8r.tfm): ['kpsewhich', u'pcrr8r.tfm'] 
find_tex_file result: /usr/share/texlive/texmf-dist/fonts/tfm/adobe/courier/pcrr8r.tfm 
opening tfm file /usr/share/texlive/texmf-dist/fonts/tfm/adobe/courier/pcrr8r.tfm 
lh=18, bc=1, ec=255, nw=2, nh=16, nd=16 
find_tex_file(pcrr8r.vf): ['kpsewhich', u'pcrr8r.vf'] 
find_tex_file result: 
Dvi._xxx: encountered special: Warning: missing glyph `Gamma' 
Dvi._xxx: encountered special: Warning: missing glyph `Delta' 
Dvi._xxx: encountered special: Warning: missing glyph `Theta' 
Dvi._xxx: encountered special: Warning: missing glyph `Lambda' 
Dvi._xxx: encountered special: Warning: missing glyph `Xi' 
Dvi._xxx: encountered special: Warning: missing glyph `Pi' 
Dvi._xxx: encountered special: Warning: missing glyph `Sigma' 
Dvi._xxx: encountered special: Warning: missing glyph `Upsilon' 
Dvi._xxx: encountered special: Warning: missing glyph `Phi' 
Dvi._xxx: encountered special: Warning: missing glyph `Psi' 
Dvi._xxx: encountered special: Warning: missing glyph `Omega' 
Dvi._xxx: encountered special: Warning: missing glyph `dotlessj' 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/9fbf3f25dbfd4f5bfc60b39bc1491553.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
find_tex_file(cmr17.tfm): ['kpsewhich', u'cmr17.tfm'] 
find_tex_file result: /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr17.tfm 
opening tfm file /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr17.tfm 
lh=18, bc=0, ec=127, nw=36, nh=16, nd=9 
find_tex_file(cmr17.vf): ['kpsewhich', u'cmr17.vf'] 
find_tex_file result: 
find_tex_file(cmmi12.tfm): ['kpsewhich', u'cmmi12.tfm'] 
find_tex_file result: /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi12.tfm 
opening tfm file /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi12.tfm 
lh=18, bc=0, ec=127, nw=97, nh=15, nd=9 
find_tex_file(cmmi12.vf): ['kpsewhich', u'cmmi12.vf'] 
find_tex_file result: 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/e2d6db7fad01b37ac8a02a8a85387ce8.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/fdbe72858be7d78500d8beb017e1c50e.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/a8016fb0d928ed1959a912a59552b382.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/cb6ad0a1dc1f50bb5ca10571c6efdf30.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/7a581e7d191e4f12ac371e0c3fcd8c81.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/36bfb83db6bed94b171b0012c6b762ee.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/dd2f7eba0d7ff3aedbaa1020460486cd.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/928f387fc89d34c34e634e0a7e62c685.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/efecb62be4d3ddc63f3078bf80db0c27.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Dvi: /home/ronen/.cache/matplotlib/tex.cache/9fbf3f25dbfd4f5bfc60b39bc1491553.dvi 
Dvi._xxx: encountered special: papersize=5203.43999pt,5203.43999pt 
Assigning font /F1 = cmr17 
find_tex_file(pdftex.map): ['kpsewhich', 'pdftex.map'] 
find_tex_file result: /var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map 
Embedding font cmr17 
Writing TrueType font 
+0

很確定這是一個已知的錯誤(#2771) – tacaswell

+0

看起來不同。從[原始郵件列表討論](http://matplotlib.1069221.n5.nabble.com/font-setting-in-matplotlib-1-3-1-td42662.html)運行代碼顯示沒有錯誤。 +這裏是乳膠特定的。 無論如何。 – Ronen

+0

還有一個問題(我從手機找不到)與pgf後端的字體查找有關。這可能是相關的(在這種情況下,它是tex,但找到字體) – tacaswell

回答

1

在Matplotlib中使用特定的後端時,您需要在導入pylab之前在之前指定此

import matplotlib as mpl 
mpl.use('agg') 
import pylab 

mpl.rcParams['text.usetex']=True 

pylab.plot(range(5)) 
pylab.savefig("test.pdf")