【发布时间】:2020-07-10 02:46:48
【问题描述】:
我正在尝试更改与 matplotlib 的注释功能一起出现的文本的字体类型(从似曾相识到让我们说 Comic sans 或 calibri)。但是,虽然我可以更改绘图中所有其他元素的字体,但它不会更改带注释的文本。有什么帮助吗?以下是我正在使用的内容以及我如何全局设置字体。在比较绘图上“1”的样式时,您会注意到字体的差异。
import numpy as np
import os, glob
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.font_manager
from matplotlib import rcParams
import pdb
matplotlib.font_manager._rebuild()
# THIS SETS ALL THE RELEVANT FONT STYLE FOR PLOTS
rcParams['font.family'] = 'sans-serif'
rcParams['font.weight'] = 'regular' #can omit this, it's the default
rcParams['font.sans-serif'] = ['calibri']
# test code
ax = plt.figure().add_subplot()
x,y = np.arange(10),np.arange(10)
ax.plot(x,y)
ax.annotate(r'$100^\circ$',
xy=(1.1, 0.1), xycoords='axes fraction',
xytext=(1.1, 0.8), textcoords='axes fraction',
arrowprops=dict(facecolor='black', shrink=0.01),
horizontalalignment='center', verticalalignment='top',
fontsize=15)
【问题讨论】:
标签: python matplotlib plot fonts annotate