You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"savefig" bug with unicode characters (version 2.0.0) #8039
I'm using Python 3.5, Numpy 1.12.0, Miktex 2.9 and Matplotlib 2.0.0.
The plot creation of the example from tex_unicode_demo.py works well.
But if I want to save this figure as a pdf-file using "plt.savefig", I get an AttributeError: 'str' object has no attribute 'decode'
This Error do not occur with an old matplotlib version (1.5.2)!!!
# -*- coding: utf-8 -*-"""This demo is tex_demo.py modified to have unicode. See that file formore information."""from __future__ importunicode_literalsimportnumpyasnpimportmatplotlibmatplotlib.rcParams['text.usetex'] =Truematplotlib.rcParams['text.latex.unicode'] =Trueimportmatplotlib.pyplotaspltplt.figure(1, figsize=(6, 4))
ax=plt.axes([0.1, 0.1, 0.8, 0.7])
t=np.arange(0.0, 1.0+0.01, 0.01)
s=np.cos(2*2*np.pi*t) +2plt.plot(t, s)
plt.xlabel(r'\textbf{time (s)}')
plt.ylabel('\\textit{Velocity (\u00B0/sec)}', fontsize=16)
plt.title(r'\TeX\ is Number $\displaystyle\sum_{n=1}^\infty'r'\frac{-e^{i\pi}}{2^n}$!', fontsize=16, color='r')
plt.grid(True)
plt.show()
plt.savefig('texDemo.pdf')
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\dviread.py", line 701, in __getitem__
result = self._font[texname.decode('ascii')]
AttributeError: 'str' object has no attribute 'decode'
This here is the full traceback. Maybe this is some problem with the backend?
I'm using Matplotlib in the software itom.
Traceback (most recent call last):
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\dviread.py", line 699, in __getitem__
result =self._font[texname]
KeyError: 'tcsi1728'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\itokrauter\desktop\matplottest.py", line 27, in <module>
plt.savefig('texDemo.pdf')
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\pyplot.py", line 697, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\figure.py", line 1572, in savefigself.canvas.print_figure(*args, **kwargs)
File "D:/itom/build/itom/itom-packages\mpl_itom\backend_itomagg.py", line 190, in print_figure
FigureCanvasAgg.print_figure(self, *args, **kwargs)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\backend_bases.py", line 2244, in print_figure**kwargs)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\backends\backend_pdf.py", line 2525, in print_pdfself.figure.draw(renderer)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\figure.py", line 1143, in draw
renderer, self, dsu, self.suppressComposite)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\axes\_base.py", line 2409, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\axis.py", line 1150, in drawself.label.draw(renderer)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\text.py", line 798, in draw
mtext=mtext)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\backends\backend_pdf.py", line 1863, in draw_tex
psfont =self.tex_font_mapping(dvifont.texname)
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\backends\backend_pdf.py", line 1566, in tex_font_mappingreturnself.tex_font_map[texfont]
File "C:\Program Files\Python\Python35\lib\site-packages\matplotlib\dviread.py", line 701, in __getitem__
result =self._font[texname.decode('ascii')]
AttributeError: 'str' object has no attribute 'decode'
#6977 is waiting for review. It won't exactly fix the actual problem here (which is probably a missing font) but it will make the error message more helpful in tracking down what exactly is missing.
It's very likely a missing PostScript font, but the error message you get is useless because the code is trying to support both strings and bytestrings but it's broken on Python 3. #6977 would fix the error message, but the fix for the underlying problem is to install whatever font is missing.
@JakobJakobson Does grep cmr10 $(kpsewhich pdftex.map) print out a line resembling "cmr10 CMR10 <cmr10.pfb"? Does kpsewhich cmr10.pfb print out a path to cmr10.pfb? If either fails, the Type-1 file for the font is not installed or the TeX font maps have not been updated to include the font, as in #8259.
I'm using Windows 10, Anaconda3-5.0.1-Windows-x86_64 and basic-miktex-2.9.6520-x64.exe, but fig.savefig('dummy.pdf') still does not work for me in Jupyter, for instance:
Activity
photoniker commentedon Feb 7, 2017
This problem can be solved if the latex package lmodern is included. But why?
tacaswell commentedon Feb 9, 2017
Can you please include the full traceback, the last line by it's self is not super useful (it lands in a
__getitem__definition).What is the value of
texnamewhen this happens (try using IPython +%debug).tacaswell commentedon Feb 9, 2017
I can not reproduce this.
photoniker commentedon Feb 10, 2017
This here is the full traceback. Maybe this is some problem with the backend?
I'm using Matplotlib in the software itom.
phobson commentedon Feb 10, 2017
@photoniker what happens if you just run the script from the command line outside of your IDE?
tacaswell commentedon Feb 10, 2017
As a side-bar, the link to
itomwas very interesting to me (at my day-job I am developing a similar system, but with very different architecture).Do you have anything non-standard in your
.matplotlibrc? That might help us to reproduce.It looks like we still have at least one place where we get the byte vs str distinction wrong.
QuLogic commentedon Feb 10, 2017
This looks related to #6977.
tacaswell commentedon Feb 10, 2017
Ah, I remembered that PR, but thought it was merged and that this was a consequence of it.
jkseppan commentedon Feb 11, 2017
#6977 is waiting for review. It won't exactly fix the actual problem here (which is probably a missing font) but it will make the error message more helpful in tracking down what exactly is missing.
photoniker commentedon Feb 13, 2017
@phobson
The same result.
@tacaswell
What do you mean with non-standard in .matplotlibrc?
jkseppan commentedon Feb 13, 2017
It's very likely a missing PostScript font, but the error message you get is useless because the code is trying to support both strings and bytestrings but it's broken on Python 3. #6977 would fix the error message, but the fix for the underlying problem is to install whatever font is missing.
photoniker commentedon Feb 13, 2017
@jkseppan
in this example here I'm using the unicode command for the degree ° characters. This one should be in every font?!
1 remaining item
jkseppan commentedon Sep 7, 2017
@JakobJakobson Does
grep cmr10 $(kpsewhich pdftex.map)print out a line resembling "cmr10 CMR10 <cmr10.pfb"? Doeskpsewhich cmr10.pfbprint out a path to cmr10.pfb? If either fails, the Type-1 file for the font is not installed or the TeX font maps have not been updated to include the font, as in #8259.cbnfreitas commentedon Nov 28, 2017
I'm using Windows 10, Anaconda3-5.0.1-Windows-x86_64 and basic-miktex-2.9.6520-x64.exe, but
fig.savefig('dummy.pdf')still does not work for me in Jupyter, for instance:I've checked
C:\Users\<uder>\AppData\Local\MiKTeX\2.9\pdftex\config\pdftex.map,and it already contains
And
kpsewhich cmr10.pfbpoints toC:/Program Files/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmr10.pfbThis is the error shown in Jupyter:
Any clue? Thanks!
jklymak commentedon Nov 28, 2017
I think #9292 should have fixed this. Looks the same. I'll close, but re-open if you think I'm mistaken. This will be in release 2.1.1.