Python Forum

Full Version: matplotlib using times italic fonts
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've download the font 'Times New Roman Italic.ttf' and copied it on
/usr/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf/Times New Roman Italic.ttf
now , if I run this frame of code here I get the correct font, but if I try to set :

 fontname = os.path.join(matplotlib.get_data_path(),
                                'fonts', 'ttf', 'Times New Roman Italic.ttf')
     self.parameters['font'] = fontname
python swich to DejavuSans give me this message :

   /usr/lib/python3.6/site-packages/matplotlib/font_manager.py:1328: UserWarning: findfont: Font family ['/usr/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf/Times New Roman Italic.ttf'] not found. Falling back to DejaVu Sans
      (prop.get_family(), self.defaultFamily[fontext]))
why ?? it is so difficult using a italic times new roman on matplotlib ?
remove whitespace in the ttf file name
sudo cp /usr/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf/Times\ New\ Roman\ Italic.ttf /usr/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf/TimesNewRomanItalic.ttf
then I modified the name inside the class :
fontname = os.path.join(matplotlib.get_data_path(),
                            'fonts', 'ttf', 'TimesNewRomanItalic.ttf')
but nothing change :

/usr/lib/python3.6/site-packages/matplotlib/font_manager.py:1328: UserWarning: findfont: Font family ['/usr/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf/TimesNewRomanItalic.ttf'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
I've solved , I wrote this line :

import matplotlib.font_manager as font_manager

font_dirs = ['/my/custom/font/dir', ]
font_files = font_manager.findSystemFonts(fontpaths=font_dirs)
font_list = font_manager.createFontList(font_files)
font_manager.fontManager.ttflist.extend(font_list)
in the base class (I've created a quality-plot hierarchy suitable for my purpose)

and then in the derived (final class) I had this line for example here times new roman :
mpl.rcParams['font.family'] = 'Times New Roman italic'
thank anyway for your help