matplotlib 中标签的字体
Font of labels in matplotlib
如何设置标签的字体?图表中的所有内容都是用拉丁现代罗马绘制的,但标签不是。我试过 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,指定 'family' 您要使用的字体:
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')
文档中有完整的 example 使用 fontdict
如何设置标签的字体?图表中的所有内容都是用拉丁现代罗马绘制的,但标签不是。我试过 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,指定 'family' 您要使用的字体:
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')
文档中有完整的 example 使用 fontdict