-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
"savefig" bug with unicode characters (version 2.0.0) #8039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This problem can be solved if the latex package lmodern is included. But why? matplotlib.rcParams['text.latex.preamble'] = [r'\usepackage{lmodern}'] |
Can you please include the full traceback, the last line by it's self is not super useful (it lands in a What is the value of |
I can not reproduce this. |
This here is the full traceback. Maybe this is some problem with the backend? 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 savefig
self.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_pdf
self.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 draw
self.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_mapping
return self.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' |
@photoniker what happens if you just run the script from the command line outside of your IDE? |
As a side-bar, the link to Do you have anything non-standard in your It looks like we still have at least one place where we get the byte vs str distinction wrong. |
This looks related to #6977. |
Ah, I remembered that PR, but thought it was merged and that this was a consequence of it. |
#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. |
The same result. @tacaswell |
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. |
@jkseppan |
What's missing is the PostScript Type-1 version of the relevant TeX
font. When installing TeX via a Linux package manager, these are often
in a separate package, such as "texlive-fonts-extra" in Ubuntu.
|
Similar problem on with Matplotlib 2.0.0 on Fedora 26. Altering the code from the file # -*- 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 numpy as np
import matplotlib
matplotlib.rcParams['text.usetex'] = True
matplotlib.rcParams['text.latex.unicode'] = True
import matplotlib.pyplot as plt
plt.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) + 2
plt.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.savefig("tmp.pdf") results in the following terminal ouput: Traceback (most recent call last):
File "/usr/lib64/python3.6/site-packages/matplotlib/dviread.py", line 699, in __getitem__
result = self._font[texname]
KeyError: 'cmr10'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib64/python3.6/site-packages/matplotlib/backends/backend_pdf.py", line 2525, in print_pdf
self.figure.draw(renderer)
File "/usr/lib64/python3.6/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python3.6/site-packages/matplotlib/figure.py", line 1143, in draw
renderer, self, dsu, self.suppressComposite)
File "/usr/lib64/python3.6/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib64/python3.6/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python3.6/site-packages/matplotlib/axes/_base.py", line 2409, in draw
mimage._draw_list_compositing_images(renderer, self, dsu)
File "/usr/lib64/python3.6/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/lib64/python3.6/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python3.6/site-packages/matplotlib/axis.py", line 1141, in draw
tick.draw(renderer)
File "/usr/lib64/python3.6/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python3.6/site-packages/matplotlib/axis.py", line 264, in draw
self.label1.draw(renderer)
File "/usr/lib64/python3.6/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib64/python3.6/site-packages/matplotlib/text.py", line 798, in draw
mtext=mtext)
File "/usr/lib64/python3.6/site-packages/matplotlib/backends/backend_pdf.py", line 1863, in draw_tex
psfont = self.tex_font_mapping(dvifont.texname)
File "/usr/lib64/python3.6/site-packages/matplotlib/backends/backend_pdf.py", line 1566, in tex_font_mapping
return self.tex_font_map[texfont]
File "/usr/lib64/python3.6/site-packages/matplotlib/dviread.py", line 701, in __getitem__
result = self._font[texname.decode('ascii')]
AttributeError: 'str' object has no attribute 'decode'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tex_unicode_demo.py", line 25, in <module>
plt.savefig("tmp.pdf")
File "/usr/lib64/python3.6/site-packages/matplotlib/pyplot.py", line 697, in savefig
res = fig.savefig(*args, **kwargs)
File "/usr/lib64/python3.6/site-packages/matplotlib/figure.py", line 1572, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/lib64/python3.6/site-packages/matplotlib/backend_bases.py", line 2244, in print_figure
**kwargs)
File "/usr/lib64/python3.6/site-packages/matplotlib/backends/backend_pdf.py", line 2531, in print_pdf
file.close()
File "/usr/lib64/python3.6/site-packages/matplotlib/backends/backend_pdf.py", line 547, in close
self.writeFonts()
File "/usr/lib64/python3.6/site-packages/matplotlib/backends/backend_pdf.py", line 647, in writeFonts
realpath, stat_key = get_realpath_and_stat(filename)
File "/usr/lib64/python3.6/site-packages/matplotlib/cbook.py", line 1030, in __call__
stat = os.stat(realpath)
FileNotFoundError: [Errno 2] No such file or directory: '/~/Downloads/cmr10' The font cmr10 however is installed as the packages texlive-collection-fontsrecommended and texlive-collection-fontsextra are installed and the fonts are also available in LibreOffice Writer. Could it be related to: https://fedoraproject.org/wiki/Changes/FontconfigCacheDirChange ? |
@JakobJakobson Does |
I tried your solution. $ kpsewhich pdftex.map
/usr/share/texlive/texmf-var/fonts/map/pdftex/updmap/pdftex.map
$ grep cmr10 $(kpsewhich pdftex.map)
$ The file pdftex.map exits but somehow the combined command shows no output. |
I found the solution for my problem. I ran |
I'm using Windows 10, Anaconda3-5.0.1-Windows-x86_64 and basic-miktex-2.9.6520-x64.exe, but
I've checked
And This is the error shown in Jupyter:
Any clue? Thanks! |
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. |
Bug report
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)!!!
The text was updated successfully, but these errors were encountered: