Python Forum
matplotlib using times italic fonts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
matplotlib using times italic fonts
#1
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 ?
Reply
#2
remove whitespace in the ttf file name
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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]))
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python-docx- change lowercase to bold, italic Tmagpy 0 1,420 Jul-01-2022, 07:25 AM
Last Post: Tmagpy
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,255 Mar-11-2021, 10:52 AM
Last Post: buran
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 6 24,103 Jun-19-2018, 03:43 PM
Last Post: JohnJSal

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020