python怎么打出来大标题_如何增加plt.title字体大小?

import matplotlib.pyplot as plt

plt.figtext(.5,.9,'Temperature', fontsize=100, ha='center')

plt.figtext(.5,.8,'Humidity',fontsize=30,ha='center')

plt.show()

也许你想要这个。您可以很容易地调整两者的fontsize,并通过更改前两个figtext位置参数来调整放置位置。

ha代表horizontal alignment

或者import matplotlib.pyplot as plt

fig = plt.figure() # Creates a new figure

fig.suptitle('Temperature', fontsize=50) # Add the text/suptitle to figure

ax = fig.add_subplot(111) # add a subplot to the new figure, 111 means "1x1 grid, first subplot"

fig.subplots_adjust(top=0.80) # adjust the placing of subplot, adjust top, bottom, left and right spacing

ax.set_title('Humidity',fontsize= 30) # title of plot

ax.set_xlabel('xlabel',fontsize = 20) #xlabel

ax.set_ylabel('ylabel', fontsize = 20)#ylabel

x = [0,1,2,5,6,7,4,4,7,8]

y = [2,4,6,4,6,7,5,4,5,7]

ax.plot(x,y,'-o') #plotting the data with marker '-o'

ax.axis([0, 10, 0, 10]) #specifying plot axes lengths

plt.show()

替代代码输出:

注:如果这段代码给出类似ImportError: libtk8.6.so: cannot open shared object file的错误,特别是Arch like systems。在这种情况下,使用sudo pacman -S tk或Follow this link安装tk


版权声明:本文为weixin_42400904原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。