Python 如何增加plt.title字体大小?

Python 如何增加plt.title字体大小?,python,matplotlib,graph,Python,Matplotlib,Graph,我正在使用Pythonsmatplotlib,这是我的代码: plt.title('Temperature \n Humidity') 我怎样才能增加温度的字体大小,而不是同时增加温度和湿度 这不起作用: plt.title('Temperature \n Humidity', fontsize=100) 假设您正在使用matplotlib渲染某些绘图 你可能想结账 下面是您案例的几行代码 plt.rc('text', usetex=True) plt.title(r"\begin{c

我正在使用Pythons
matplotlib
,这是我的代码:

  plt.title('Temperature \n Humidity')
我怎样才能增加温度的字体大小,而不是同时增加温度和湿度

这不起作用:

 plt.title('Temperature \n Humidity', fontsize=100)

假设您正在使用matplotlib渲染某些绘图

你可能想结账

下面是您案例的几行代码

plt.rc('text', usetex=True)
plt.title(r"\begin{center} {\Large Temperature} \par {\large Humidity} \end{center}")

希望有帮助

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()
也许你想要这个。通过更改前两个
figtext
位置参数,可以轻松调整这两个参数的
fontsize
,并调整其放置位置。 哈是

或者

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()
备选代码的输出:


PS:如果此代码给出错误,如
ImportError:libtk8.6.so:无法打开共享对象文件
特别是在
Arch-like系统中
。在这种情况下,使用sudo pacman-S tk安装
tk
或这在Matplotlib的最新版本(目前为2.0.2)中对我来说最有效。这有助于生成演示文稿图形:

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)
奇数for循环结构似乎是调整每个tic标签大小所必需的。
此外,应在调用
plt.show(block=True)
之前调用上述函数,否则无论出于何种原因,标题大小偶尔保持不变。

fontsize可在字典fontdict中指定,该字典提供了额外的参数fontwweight、垂直对齐、,水平对齐

下面的代码片段应该可以工作


plt.title('Temperature\n湿度',fontdict={'fontsize':100})

我不想详细讨论这个图表 通用方法: 第一步-在主标题和图表之间留出距离:

from matplotlib import rcParams
rcParams['axes.titlepad'] = 20 
然后通过设置坐标插入字幕:

ax.text(0.3, -0.56, 'subtitle',fontsize=12)
只需执行以下操作:
ax.set\u title('这是标题',fontsize=20)

您好,.5、.9是什么?我已经在这里指定了。这些是标题的位置参数。你也可以这样说。一个用于x轴,一个用于y轴。只要试着操纵它们,你就会明白;e、 例如,文本“湿度”刚好低于“温度”,因此我将其放置在y轴位置的下方,如.8,其中x轴位置参数与“温度”参数相同,即.5。Hi-Meher,我怎样才能让figtext显示在图形的顶部而不是图上呢?或者说,使用
figtext
,它可能不可能实现;除了相应地调整字体大小和位置参数。您应该发布更多的代码和一些示例数据。现在我发布了一个不同的代码;但是,如果您正在进行项目/已经绘制了数据,那么这将对您造成问题/困扰。请参阅更新的代码。您好,我收到一个错误,说明ax未定义。这应该是公认的答案。比公认的答案简单20倍。我发现