如何更改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屋!
查看全文