Python Matplotlib使用“时设置标题粗体”;《新罗马时报》;

Python Matplotlib使用“时设置标题粗体”;《新罗马时报》;,python,matplotlib,Python,Matplotlib,最初,我可以通过以下方式将地物标题设置为粗体: import Matplotlib.pyplot as plt plt.title("Test",fontweight="bold") 但一旦我使用了fontname=“Times New Roman”,fontwweight=“bold”就不会产生任何变化: import Matplotlib.pyplot as plt plt.title("Test",fontname="Times New Roman",fontweight="bold

最初,我可以通过以下方式将地物标题设置为粗体:

import Matplotlib.pyplot as plt

plt.title("Test",fontweight="bold")
但一旦我使用了
fontname=“Times New Roman”
fontwweight=“bold”
就不会产生任何变化:

import Matplotlib.pyplot as plt

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

如何将地物标题设置为粗体?

假设您的系统上安装了粗体times字体,则该字体有自己的粗体times字体:

plt.title("Test", fontname="Times New Roman Bold")
您可以在此处找到系统上的字体列表:

我有:

>>> [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']

在linux和mac上,泰晤士报新罗马版的粗体字体似乎比普通字体更容易选择。这就是为什么你看不到将正常设置为粗体的变化,它已经是粗体了

我知道这个问题已经很老了,但它仍然是一个问题,至少对我的mac来说,当你想使用普通的时候。我发现了这个问题的一个非常简单的解决方案,由azag0发布在github上

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


如果执行此操作,则在设置
fontwweight=bold
时会看到更改,因为正确选择了标准参数。

fontwweight是fig.suptitle()函数的参数。 所以这应该对你有用,
fig.suptitle(“Test”,fontwweight='bold')

Hmmm…..这对我来说很有效。我也看到了这个解决方案,但似乎无法实现。我必须把代码片段放在哪里?加载matplot.lib之后应该可以,在您尝试调整FontWeights之前,尽管我有所有这些字体(省略了所有路径,只有一个):['/usr/share/fonts/truetype/msttcorefonts/timesbd.ttf',Times\u New\u Roman\u Bold.ttf',Times\u New\u Roman.ttf',timesi.ttf',Times\u New Roman\u Bold\u Italic.ttf',timesbi.ttf',Times.ttf',Times\u New Roman\u Italic.ttf']我收到以下错误:font\u manager.py 1241:UserWarning:findfont font-family['Times New Roman-Bold']找不到。返回到DejaVu SAN。(prop.get_family(),self.defaultFamily[fontext]))