30

Originally I can set the figure title to bold by the following:

import matplotlib.pyplot as plt

plt.title("Test", fontweight="bold")

Yet once I use fontname="Times New Roman", fontweight="bold" just won't result in any change at all:

import matplotlib.pyplot as plt

plt.title("Test", fontname="Times New Roman", fontweight="bold")

How shall I set the figure title to bold?

Only god knows
  • 307
  • 1
  • 10
wdg
  • 1,687
  • 5
  • 17
  • 29

3 Answers3

15

fontweight is the argument for the fig.suptitle() function. So this should work for you, fig.suptitle("Test",fontweight='bold')

Nikhil Valiveti
  • 339
  • 6
  • 13
13

There's a bold times font of its own, assuming it's installed on your system:

plt.title("Test", fontname="Times New Roman Bold")

You can find a list of fonts on your system here: How to get a list of all the fonts currently available for Matplotlib?

I have:

>>> [i for i in matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
if 'times' in i.lower()]
['/Library/Fonts/Times New Roman.ttf',
 '/Library/Fonts/Times New Roman Italic.ttf',
 '/Library/Fonts/Times New Roman Bold Italic.ttf',
 '/Library/Fonts/Times New Roman Bold.ttf']
Community
  • 1
  • 1
askewchan
  • 45,161
  • 17
  • 118
  • 134
  • 1
    Although I have all these fonts (omitted the all the paths but one): ['/usr/share/fonts/truetype/msttcorefonts/timesbd.ttf', 'Times_New_Roman_Bold.ttf', 'Times_New_Roman.ttf', 'timesi.ttf', 'Times_New_Roman_Bold_Italic.ttf', 'timesbi.ttf', 'times.ttf', 'Times_New_Roman_Italic.ttf'] I get this error: font_manager.py:1241: UserWarning: findfont: Font family ['Times New Roman Bold'] not found. Falling back to DejaVu Sans. (prop.get_family(), self.defaultFamily[fontext])) – Homero Esmeraldo Feb 26 '19 at 08:01
3

On linux and mac the bold font of TImes New Roman appears to get choosen over the normal one. That is why you don't see changes setting hte normal one to bold, it already is bold.

I know the question is very old, but it still is a problem, at least for me on my mac, when you want to use the normal one. I found a very easy solution to this problem, posted by azag0 on github

del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()

https://github.com/matplotlib/matplotlib/issues/5574

If you do this, you will see changes when you set fontweight=bold , as the standard one is choosen correctly.

dennis
  • 707
  • 1
  • 8
  • 12
  • I also saw this solution but can't seem to get it to work. Where exactly do I have to put that snippet? – Readler Jan 31 '19 at 18:14
  • Right after loading matplot.lib in should be fine, necessarily before you try to adjust the fontweight – dennis Feb 01 '19 at 19:42