为 matplotlib 图例指定字体粗细的最佳方法是什么?我可以使用:
matplotlib.rcParams.update({'legend.fontsize':12})
设置字体大小但是当我使用
matplotlib.rcParams.update({'legend.fontweight':'bold'}
它提示“'legend.fontweight' 不是有效的 rc 参数”
请您参考如下方法:
您可以使用 prop argument 将参数传递到 plt.legend .这本词典允许您选择 text properties为了传说。
import matplotlib
import matplotlib.pyplot as plt
legend_properties = {'weight':'bold'}
plt.plot([1,2,3], [4,5,6], label='Test')
plt.legend(prop=legend_properties)
plt.show()
