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

Add two names (.format) to matplotlib graph

我正在尝试使用两个循环为我的图表添加两种格式的标题,但在 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']
markers = ['dotted', '-']

fig, axes = plt.subplots(1, 2)

# then we plot using the above `axes`
for graph in range(2):
    axes[graph].plot([1, 2], [1, 2], ls=markers[graph])
    axes[graph].set_title(f'Graph {graph}: {types[graph]}')