Repository navigation
Closed
Description
Recently, after the matplotlib 1->2 update, some plots that worked in 1.5.3 stoped working in this new version. All of them use tex rendering for texts and math. Latex is correctly installed and the package is installed inside Anaconda 4.2.0.
If I set only
import matplotlib.pyplot as plt
import matplotlib
plt.rc('text', usetex=True)
matplotlib.rcParams.update({'font.size': 14})
The following errors are raised:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/home/julio/.anaconda3/lib/python3.5/site-packages/matplotlib/dviread.py in __getitem__(self, texname)
698 try:
--> 699 result = self._font[texname]
700 except KeyError:
KeyError: 'cmr10'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
/home/julio/.anaconda3/lib/python3.5/site-packages/matplotlib/backends/backend_pdf.py in print_pdf(self, filename, **kwargs)
2524 bbox_inches_restore=_bbox_inches_restore)
-> 2525 self.figure.draw(renderer)
2526 renderer.finalize()
...
/home/julio/.anaconda3/lib/python3.5/site-packages/matplotlib/dviread.py in __getitem__(self, texname)
700 except KeyError:
--> 701 result = self._font[texname.decode('ascii')]
702 fn, enc = result.filename, result.encoding
AttributeError: 'str' object has no attribute 'decode'
During handling of the above exception, another exception occurred:
FileNotFoundError Traceback (most recent call last)
<ipython-input-3-778cf2a0d47b> in <module>()
37 plot_twiny(ax[0], 1850, 2020, 3)
38
---> 39 fig.savefig('./fig/ligth_curves.pdf')
40
41 plt.show()
...
/home/julio/.anaconda3/lib/python3.5/site-packages/matplotlib/cbook.py in __call__(self, path)
1028 stat_key = realpath
1029 else:
-> 1030 stat = os.stat(realpath)
1031 stat_key = (stat.st_ino, stat.st_dev)
1032 result = realpath, stat_key
FileNotFoundError: [Errno 2] No such file or directory: '/home/julio/Documents/docs/Artigos/Artigo 01 - R40 e R110/cmr10'
But, if I change the fonts to palatino, this plot is processed OK, but another plot in the same document raises similar error, but with "cmsy10" fonts.
Reacted by Gilles Callebaut, PhD and Max
Activity
tacaswell commentedon Mar 10, 2017
Can you give an example of what you are doing that triggers this?
Possibly related to #8039 and #6516
tacaswell commentedon Mar 10, 2017
I can not reproduce this with a clean installation
juliotux commentedon Mar 10, 2017
Doing a simple plot inside Jupyter notebook.
The same error is returned:
Running the same example inside an ipython terminal, the same occurs.
juliotux commentedon Mar 10, 2017
No problem if save as
pngorjpeg.tacaswell commentedon Mar 10, 2017
FileNotFoundError: [Errno 2] No such file or directory: '/home/julio/Documents/cmr12'that seems wrong, not sure why it is looking there for the fonts.Can you try removing all of the files in
~/.cache/matplotlib?juliotux commentedon Mar 10, 2017
I removed the matplotlib cache before and tried again, without success. As aditional information, this problem only occurs when save plots as
pdfformat.juliotux commentedon Mar 10, 2017
Problem fixed generating a local map of fonts using
updmapcommand. Apparently, Arch Linux don't do it when installing texlive.anntzer commentedon Mar 10, 2017
How did you install texlive? Arch package or repo?
Hooks seem to be defined: https://git.archlinux.org/svntogit/packages.git/tree/trunk/texlive-updmap.hook?h=packages/texlive-bin, https://git.archlinux.org/svntogit/packages.git/tree/trunk/texlive-updmap.script?h=packages/texlive-bin
juliotux commentedon Mar 10, 2017
Installed from default Arch package with
pacman. The main problem I think is that the Matplotlib requires a local map of fonts, which is not created by the package, that creates only a system version of it.Now I think the question is: why do Matplolib 1.5.3 runs normally without this local map and 2.0 doesn't?
13 remaining items
jkseppan commentedon Aug 3, 2017
Reproduction instructions: I used Linode's "Arch 2017.07.1" and ran
and accepted all defaults. Then I started
ipythonand ran the following:I got a similar error as reported above.
jkseppan commentedon Aug 3, 2017
The command
updmap --cnffile /etc/texmf/web2c/updmap.cfg -sysfixes the map files so that the cmr12 font is found, and the script works. Before that command none of the map files I could find included that font.ClaymorePT commentedon Aug 3, 2017
andrmnl commentedon Aug 3, 2017
jkseppan commentedon Aug 3, 2017
I think I agree with the comment saying that this is an Arch Linux configuration issue rather than a Matplotlib bug. The error message could be clearer, though.
Possibly related: the following commit deletes the upstream updmap configuration, commenting that it "contains too many maps".
https://git.archlinux.org/svntogit/packages.git/commit/trunk/PKGBUILD?h=packages/texlive-core&id=7eaea8d4f608f13bb5afc4394ed6f4624ded1fd4
andrmnl commentedon Aug 3, 2017
felixonmars commentedon Aug 3, 2017
Adds some info: I was getting a (maybe) similar problem with pypandoc's test suite: JessicaTegner/pypandoc#132
jkseppan commentedon Aug 4, 2017
lisette-espin commentedon Apr 1, 2019
You just need to make sure all your text follows LaTex conventions.
Eg. "% coverage" --> r"$%coverage$"
anntzer commentedon Jan 24, 2021
FWIW I cannot reproduce this anymore using a clean Arch Linux docker image and @jkseppan's instructions. I'll optimistically assume that this has been fixed in the meantime either on Arch's side or on Matplotlib's side, but feel free to reopen with a more recent repro.