指定字体系列:
如果您只知道ttf的路径,则可以使用以下
get_name方法发现字体系列名称:
import matplotlib as mplimport matplotlib.pyplot as pltimport matplotlib.font_manager as font_managerpath = '/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf'prop = font_manager.FontProperties(fname=path)mpl.rcParams['font.family'] = prop.get_name()fig, ax = plt.subplots()ax.set_title('Text in a cool font', size=40)plt.show()
通过路径指定字体:
import matplotlib.pyplot as pltimport matplotlib.font_manager as font_managerpath = '/usr/share/fonts/truetype/msttcorefonts/Comic_Sans_MS.ttf'prop = font_manager.FontProperties(fname=path)fig, ax = plt.subplots()ax.set_title('Text in a cool font', fontproperties=prop, size=40)plt.show()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)