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
def plt_resize_text(labelsize, titlesize):
ax = plt.subplot()
for ticklabel in (ax.get_xticklabels()):
ticklabel.set_fontsize(labelsize)
for ticklabel in (ax.get_yticklabels()):
ticklabel.set_fontsize(labelsize)
ax.xaxis.get_label().set_fontsize(labelsize)
ax.yaxis.get_label().set_fontsize(labelsize)
ax.title.set_fontsize(titlesize)
也许你想要这个。您可以很容易地调整两者的
fontsize
,并通过更改前两个figtext
位置参数来调整放置位置。 ha代表horizontal alignment或者
替代代码输出:
注:如果这段代码给出类似
ImportError: libtk8.6.so: cannot open shared object file
的错误,特别是Arch like systems
。在这种情况下,使用sudo pacman -S tk
或Follow this link安装tk
这在最近的Matplotlib版本(目前是2.0.2)中对我来说是最有效的。它有助于生成演示图形:
奇怪的for循环结构似乎有必要调整每个tic标签的大小。 另外,上面的函数应该在调用
plt.show(block=True)
之前调用,否则无论出于什么原因,标题大小偶尔都会保持不变。fontsize可以在字典中指定,它提供了其他参数fontwweight、verticalalignment、horizontalignment
下面的代码片段应该可以工作
plt.title('Temperature \n Humidity', fontdict = {'fontsize' : 100})
相关问题 更多 >
编程相关推荐