Wheezy: loading matplotlib, error 'ItalicAngle' in AFM files

Need help with C, C++, perl, python, etc?

Wheezy: loading matplotlib, error 'ItalicAngle' in AFM files

Postby michapma » 2015-03-03 21:29

I've been teaching myself Python-based numerical analysis for use at work, as I'm tired of Excel, Matlab isn't an option, and Octave's graphics capabilities don't suit me. (R is also great, but not for everything.) Since I do most serious work on Wheezy rather than Sid, I installed the needed Python packages including ipython, python-numpy, python-scipy, python-matplotlib, python-pandas and spyder (as IDE). While following a tutorial for pandas in ipython, I discovered that importing the matplotlib module as is usual quite unexpectedly produces errors. The following is a traceback from a fresh ipython session.

Code: Select all
In [1]: import matplotlib.pyplot as plt
Value error parsing header in AFM: ItalicAngle -9,9
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-1-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt

/usr/lib/pymodules/python2.7/matplotlib/pyplot.py in <module>()
     21 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
     22 from matplotlib import docstring
---> 23 from matplotlib.figure import Figure, figaspect
     24 from matplotlib.backend_bases import FigureCanvasBase
     25 from matplotlib.image import imread as _imread

/usr/lib/pymodules/python2.7/matplotlib/figure.py in <module>()
     16 import artist
     17 from artist import Artist, allow_rasterization
---> 18 from axes import Axes, SubplotBase, subplot_class_factory
     19 from cbook import flatten, allequal, Stack, iterable, is_string_like
     20 import _image

/usr/lib/pymodules/python2.7/matplotlib/axes.py in <module>()
     12 import matplotlib.artist as martist
     13 from matplotlib.artist import allow_rasterization
---> 14 import matplotlib.axis as maxis
     15 import matplotlib.cbook as cbook
     16 import matplotlib.collections as mcoll

/usr/lib/pymodules/python2.7/matplotlib/axis.py in <module>()
      8 from matplotlib.artist import allow_rasterization
      9 import matplotlib.cbook as cbook
---> 10 import matplotlib.font_manager as font_manager
     11 import matplotlib.lines as mlines
     12 import matplotlib.patches as mpatches

/usr/lib/pymodules/python2.7/matplotlib/font_manager.py in <module>()
   1323             verbose.report("Using fontManager instance from %s" % _fmcache)
   1324     except:
-> 1325         _rebuild()
   1326
   1327     def findfont(prop, **kw):

/usr/lib/pymodules/python2.7/matplotlib/font_manager.py in _rebuild()
   1273 def _rebuild():
   1274     global fontManager
-> 1275     fontManager = FontManager()
   1276     pickle_dump(fontManager, _fmcache)
   1277     verbose.report("generated new fontManager")

/usr/lib/pymodules/python2.7/matplotlib/font_manager.py in __init__(self, size, weight)
    997         self.afmfiles = findSystemFonts(paths, fontext='afm') + \
    998             findSystemFonts(fontext='afm')
--> 999         self.afmlist = createFontList(self.afmfiles, fontext='afm')
   1000         self.defaultFont['afm'] = None
   1001

/usr/lib/pymodules/python2.7/matplotlib/font_manager.py in createFontList(fontfiles, fontext)
    565                 verbose.report("Could not parse font file %s"%fpath)
    566                 continue
--> 567             prop = afmFontProperty(fpath, font)
    568         else:
    569             try:

/usr/lib/pymodules/python2.7/matplotlib/font_manager.py in afmFontProperty(fontpath, font)
    482     #  Styles are: italic, oblique, and normal (default)
    483
--> 484     if font.get_angle() != 0 or name.lower().find('italic') >= 0:
    485         style = 'italic'
    486     elif name.lower().find('oblique') >= 0:

/usr/lib/pymodules/python2.7/matplotlib/afm.pyc in get_angle(self)
    466     def get_angle(self):
    467         "Return the fontangle as float"
--> 468         return self._header['ItalicAngle']
    469
    470     def get_capheight(self):

KeyError: 'ItalicAngle'

In [2]:


The result is that matplotlib is unusable and I cannot plot. What I could find through web search confirmed that others have experienced the problem, sometimes related to matplotlib, which is due to commas being used instead of periods as a delimiter in certain AFM font files that matplotlib calls.

http://maxshaptala.blogspot.ch/2014/04/ ... heezy.html (in Russian)
According to a translation, recommends something to do with fontList.cache and ${HOME}/.matplotlib, with a download link. Not doing something I can't read from a source I don't know.

http://itnovella.ru/itnovella/2013/10/2 ... heezy.html (also in Russian)
Recommends changing the delimiter '.' to ',' in the parameter ItalicAngle in files with extension afm in directory /usr/share/fonts/X11/Type1/. The blog entry goes on to suggest identifying the files with the command
Code: Select all
grep 'ItalicAngle* [0-9\-]*[\,]' /usr/share/fonts/X11/Type1/*.afm

and automating the delimiter replacement with a bash script
Code: Select all
#!/bin/bash
for i in $(grep -l "ItalicAngle* [0-9\-]*[\,]" /usr/share/fonts/X11/Type1/*.afm);
    do sed -i '/ItalicAngle/s/,/./' $i;
done;
echo "ok"


In the comments, a reader comments on August 24, 2014 that the bug remains:
https://bugs.debian.org/cgi-bin/bugrepo ... bug=691916

This bug report of matplotlib crashing was filed in October 2012 against version 1.1.1~rc2-1, which is still the present version in Wheezy. It specifically mentions the program rst2pdf, which is not installed on my machine. The program obviously calls matplotlib, as it gives the same ItalicAngle error when parsing AFM files. A proposed patch apparently creates more problems than it solves, and the issue has been called a bug in the AFM file.

While one could suppose that matplotlib should handle such an error with more grace, the only solution to using matplotlib on Wheezy appears to be to replace the commas with periods in the relevant AFM files, as outlined in the bug report on the offending package t1-cyrillic:

https://bugs.debian.org/cgi-bin/bugrepo ... bug=694493

The bug discussion discloses that, while the periods are present in Jessie, the error-producing commas are the result of compilation under certain locales (specifically Russian) and could easily reappear. The proposed solution should be to make the build independent locale.

I wrote most of this for the sake of documentation, but I do have a question. If I make this substitution, can I rest assured that the future upgrade to Jessie will simply overwrite the AFM files?

Cheers,
Mike
User avatar
michapma
 
Posts: 539
Joined: 2008-05-04 20:49
Location: Prague

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

fashionable