Python 将两个名称(.format)添加到matplotlib图形

Python 将两个名称(.format)添加到matplotlib图形,python,matplotlib,plot,graph,title,Python,Matplotlib,Plot,Graph,Title,我试图使用两个循环,用两种格式为我的图形添加标题,但所需的结果并没有在Python中的Matplotlib中显示出来。目标是两个标题如下的图表: 第一幅图:“图1:点” 第二幅图:“图2:线” 这是我一直在尝试的代码: types = ['Dots','Lines'] for graph in range(2): ax = fig.add_subplot(1,2,graph+1, aspect='equal') plt.imshow(myarray[graph],extent

我试图使用两个循环,用两种格式为我的图形添加标题,但所需的结果并没有在Python中的Matplotlib中显示出来。目标是两个标题如下的图表:

第一幅图:“图1:点”

第二幅图:“图2:线”

这是我一直在尝试的代码:

types = ['Dots','Lines']

for graph in range(2):
    ax  = fig.add_subplot(1,2,graph+1, aspect='equal')
    plt.imshow(myarray[graph],extent = extent)
       
    plt.xlabel('X',fontsize=5)
    plt.ylabel('Y',fontsize=5)
    plt.colorbar(shrink=1.0)
    
    for name in types:
        plt.title('Graph {}: {}'.format(graph+1, name),fontsize = 10)

非常感谢您为简化此过程提供的任何帮助,请提前感谢!;)

您可以保存子批次轴以直接索引

下面是一个索引轴、标题和线型的玩具示例:

types=['Dots','Lines']
标记=['点','-']
图,轴=plt子批次(1,2)
#然后我们用上面的坐标轴作图`
对于范围(2)内的图形:
轴[图形]。绘图([1,2],[1,2],ls=标记[图形])
轴[graph].set_title(f'graph{graph}:{types[graph]}')

非常有魅力!非常感谢