画图图例字体"/>
python画图图例字体
通过prop参数将FontProperties对象(如下面的font)传递给ax.legend:import matplotlib.pyplot as plt
import numpy as np
import matplotlib.font_manager as font_manager
fig, ax = plt.subplots()
x = np.linspace(-10, 10, 100)
ax.plot(np.sin(x)/x, label='Mexican hat')
font = font_manager.FontProperties(family='Comic Sans MS',
weight='bold',
style='normal', size=16)
ax.legend(prop=font)
plt.show()
在Ubuntu上,你可以通过运行fc-cache -f -v /path/to/fonts/directory
我不确定在其他操作系统上是如何实现的,也不知道在其他类型的Unix上是如何通用的。
一旦您安装了字体以便操作系统了解它们,您就可以通过删除~/.cache/fontconfig和~/.cache/matplotlib中的文件,使matplotlib regenerate its fontList。
~/.cache/matplotlib/fontList.json文件提供了matplotlib所知道的所有字体的可读列表。在这里,您将发现如下条目:{<
更多推荐
python画图图例字体
发布评论