Matplotlib setting title bold while using “Times New Roman”

前端 未结 3 663
野的像风
野的像风 2021-01-04 05:48

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

import Matplotlib.pyplot as plt

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

bu

相关标签:
3条回答
  • 2021-01-04 06:40

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

    0 讨论(0)
  • 2021-01-04 06:50

    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']
    
    0 讨论(0)
  • 2021-01-04 06:50

    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.

    0 讨论(0)
提交回复
热议问题