使用Matplotlib为图中的子图添加A、B、C注释 要使用matplotlib为图中的子图添加A、B和C的注释,我们可以采取以下步骤: 设置图大小并调整子图之间和周围的边距。 创建一个带有 nrows=1 和 ncols=3 的子图集。 创建一个一维数组迭代器。 迭代每个轴并显示数据作为图像。 在循环本身中,放置文本A、B和C。 使用 show() 方法显示图表。 示例 import numpy as np from matplotlib import pyplot as plt import string plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, axs = plt.subplots(1, 3) axs = axs.flat for index, ax in enumerate(axs): ax.imshow(np.random.randn(4, 4), interpolation='nearest',cmap="copper") ax.text(0.45, 1.1, string.ascii_uppercase[index],transform=ax.transAxes, size=20, weight='bold') plt.show() PythonCopy 输出