不改变默认字体的情况下更改字体名称的Python方法

5
我曾尝试使用 New Times New Roman 字体替换默认的 Bitstream vera sans font ,但在学校网络服务器上,我用 TimesHelveticaArial 字体时出现以下错误:

not found error

为解决此问题,我向技术支持询问并上传了这些字体。我确认它们已经上传成功。现在,我删除了 fontList.cache 并重新运行以下代码:
import matplotlib.pyplot as plt
import numpy as np
x= np.arange(0,100)
y= 3*x-1
plt.plot(x,y)
plt.xlabel('x',fontdict={"name": "Times New Roman"})
plt.ylabel('y',fontdict={"name": "Times New Roman"})
plt.show()

好消息是我不再看到错误信息了,但坏消息是在添加 fontdict={"name": "Times New Roman"} 后,标签消失了。

我无法找到没有错误的原因。

1个回答

2

我相信你可以直接使用:

    plt.xlabel('x', fontname = 'Times New Roman')
    plt.ylabel('y', fontname = 'Times New Roman')

我认为您的错误来自于对fontdict的不正确使用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接