Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

python - 如何在Matplotlib中设置图标题和轴标签字体大小?(How do I set the figure title and axes labels font size in Matplotlib?)

I am creating a figure in Matplotlib like this:

(我正在Matplotlib中创建一个像这样的人物:)

from matplotlib import pyplot as plt

fig = plt.figure()
plt.plot(data)
fig.suptitle('test title')
plt.xlabel('xlabel')
plt.ylabel('ylabel')
fig.savefig('test.jpg')

I want to specify font sizes for the figure title and the axis labels.

(我想指定图标题和轴标签的字体大小。)

I need all three to be different font sizes, so setting a global font size ( mpl.rcParams['font.size']=x ) is not what I want.

(我需要三个不同的字体大小,所以设置全局字体大小( mpl.rcParams['font.size']=x )不是我想要的。)

How do I set font sizes for the figure title and the axis labels individually?

(如何单独设置图标题和轴标签的字体大小?)

  ask by vasek1 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Functions dealing with text like label , title , etc. accept parameters same as matplotlib.text.Text .

(处理labeltitle等文本的函数接受与matplotlib.text.Text相同的参数。)

For the font size you can use size/fontsize :

(对于字体大小,您可以使用size/fontsize :)

from matplotlib import pyplot as plt    

fig = plt.figure()
plt.plot(data)
fig.suptitle('test title', fontsize=20)
plt.xlabel('xlabel', fontsize=18)
plt.ylabel('ylabel', fontsize=16)
fig.savefig('test.jpg')

For globally setting title and label sizes, mpl.rcParams contains axes.titlesize and axes.labelsize .

(对于全局设置titlelabel大小, mpl.rcParams包含axes.titlesizeaxes.labelsize 。)

(From the page):

((来自页面):)

axes.titlesize      : large   # fontsize of the axes title
axes.labelsize      : medium  # fontsize of the x any y labels

(As far as I can see, there is no way to set x and y label sizes separately.)

((据我所知,没有办法单独设置xy标签尺寸。))

And I see that axes.titlesize does not affect suptitle .

(我看到axes.titlesize不会影响suptitle 。)

I guess, you need to set that manually.

(我想,你需要手动设置。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...