Python Matplotlib 在使用“Times New Roman”时将标题设置为粗体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18962063/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Matplotlib setting title bold while using "Times New Roman"
提问by wdg
Originally I can set the figure title to bold by the following:
最初我可以通过以下方式将图形标题设置为粗体:
import Matplotlib.pyplot as plt
plt.title("Test",fontweight="bold")
but once I use fontname="Times New Roman"
, fontweight="bold"
just won't result in any change at all:
但是一旦我使用fontname="Times New Roman"
,fontweight="bold"
就根本不会导致任何变化:
import Matplotlib.pyplot as plt
plt.title("Test",fontname="Times New Roman",fontweight="bold")
How shall I set the figure title to bold?
如何将图形标题设置为粗体?
回答by askewchan
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?
您可以在此处找到系统上的字体列表:如何获取当前可用于 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']
回答by dennis
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.
在 linux 和 mac 上,粗体字体 TImes New Roman 似乎比普通字体更受欢迎。这就是为什么您看不到将普通的设置为粗体的更改,它已经是粗体。
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
我知道这个问题很老了,但它仍然是一个问题,至少对我在我的 mac 上来说,当你想使用普通的时候。我找到了一个非常简单的解决这个问题的方法,由 azag0 在 github 上发布
del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()
https://github.com/matplotlib/matplotlib/issues/5574
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.
如果您这样做,您将在设置时看到更改fontweight=bold
,因为正确选择了标准。