matplotlib中使用相对坐标确定标注位置

我有一组2*3的 subplots ,每个的 xlimylim 都不一样,但是我想在每个子图的相同位置进行标注,怎么办呢?这个时候可以用相对坐标,在 ax.text 中specify transform=ax.transAxes

from matplotlib import pyplot as plt

fig, axes = plt.subplots(2,3)
xlims = (
	[1,2], [2,3], [3,4],
    [4,5], [5,6], [6,7]
)
ylims = (
    [4,5], [5,6], [6,7],
	[1,2], [2,3], [3,4]
)
for ind in range(6):
    row, col = ind // 3, ind % 3
    ax = axes[row, col]
    ax.set_xlim(xlims[ind])
    ax.set_ylim(ylims[ind])
    ax.text(
        0.2, 0.1, 'some text',
        horizontalalignment='center',  # 水平居中
        verticalalignment='center',  # 垂直居中
        transform=ax.transAxes  # 使用相对坐标
    )

matplotlib中使用相对坐标确定标注位置_第1张图片

你可能感兴趣的:(#,pandas,&,numpy,&,matplotlib,matplotlib,python)