如何更改 matplotlib 图上的字体大小 [英] How to change the font size on a matplotlib plot
本文介绍了如何更改 matplotlib 图上的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更改 matplotlib 图中所有元素(刻度、标签、标题)的字体大小?
How does one change the font size for all elements (ticks, labels, title) on a matplotlib plot?
我知道如何更改刻度标签大小,这是通过以下方式完成的:
I know how to change the tick label sizes, this is done with:
import matplotlib
matplotlib.rc('xtick', labelsize=20)
matplotlib.rc('ytick', labelsize=20)
但是如何改变其余的呢?
But how does one change the rest?
推荐答案
来自 matplotlib 文档、
font = {'family' : 'normal',
'weight' : 'bold',
'size' : 22}
matplotlib.rc('font', **font)
这会将所有项目的字体设置为 kwargs 对象指定的字体,font
.
This sets the font of all items to the font specified by the kwargs object, font
.
或者,您也可以按照 中的建议使用 rcParams
update
方法这个答案:
Alternatively, you could also use the rcParams
update
method as suggested in this answer:
matplotlib.rcParams.update({'font.size': 22})
或
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 22})
您可以在自定义 matplotlib 页面上找到可用属性的完整列表.
You can find a full list of available properties on the Customizing matplotlib page.
这篇关于如何更改 matplotlib 图上的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文