Python matplotlib:为所有图形(非子地块)设置单一标题

Python matplotlib:为所有图形(非子地块)设置单一标题,python,pandas,matplotlib,spyder,title,Python,Pandas,Matplotlib,Spyder,Title,我想给代码中的所有数字一个标题#Variable_cycles。数字不是子地块,而是单独绘制的。我正在使用%matplotlib在单独的窗口中显示绘图。据我所知,plt.rcParams没有这样的密钥 导入matplotlib.pyplot作为plt %matplotlib plt.图(1),plt.散射(x,y,marker='o'), 产品名称(“可变循环”), 节目 plt.图(2), plt.scatter(x,y,marker='*'), 产品名称(“可变循环”), 节目 我不相信rc

我想给代码中的所有数字一个标题
#Variable_cycles
。数字不是子地块,而是单独绘制的。我正在使用%matplotlib在单独的窗口中显示绘图。据我所知,plt.rcParams没有这样的密钥

导入matplotlib.pyplot作为plt
%matplotlib
plt.图(1),plt.散射(x,y,marker='o'),
产品名称(“可变循环”),
节目
plt.图(2),
plt.scatter(x,y,marker='*'),
产品名称(“可变循环”),
节目

我不相信rcParams或类似文件中有这样的设置,但如果您为所有地物设置了选项,您可以创建一个简单的辅助函数来创建地物,应用这些设置(例如标题、轴标签等),然后返回地物对象,然后,您只需要为每个新图形调用该函数一次。一个简单的示例是:

import matplotlib.pyplot as plt

%matplotlib

def makefigure():
    
    # Create figure and axes
    fig, ax = plt.subplots()
    
    # Set title
    fig.suptitle('Variable cycles')

    # Set axes labels
    ax.set_xlabel('My xlabel')
    ax.set_ylabel('My ylabel')

    # Put any other common settings here...

    return fig, ax

fig1, ax1 = makefigure()
ax1.scatter(x, y, marker='o')           

fig2, ax2 = makefigure()
ax2.scatter(x, y, marker='*')