如何设置标签字体?图中的所有内容均使用Latin Modern Roman绘制,但标签未绘制。我尝试了csfont,但没有帮助。
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
plt.rcParams["font.family"] = "Latin Modern Roman"
csfont = {'fontname':'Latin Modern Roman'}
plt.xlabel(r'$\it{Label2}$', fontsize=14)
plt.ylabel(r'$\it{Label1}$ (eV)', fontsize=14, **csfont)
我为ylabel尝试了这个:
plt.ylabel(r'$\it{Excitační energie}$ (eV)', family='Latin Modern Roman', fontsize=14)
这是结果:
您可以传递带有字体参数的fontdict,并指定要使用的字体的“系列”:
font = {'family': 'Latin Modern Roman',
'color': 'darkred',
'weight': 'normal',
'size': 16,
}
plt.ylabel('label-text', fontdict=font)
或在标签中设置家庭:
plt.ylabel('label-text', family='Latin Modern Roman')
在文档中有一个使用fontdict的完整示例
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句