在 seaborn replot 或 facetgrid 中添加带有标签的自定义箭头

Adding custom arrows with labels in seaborn relplot or a facetgrid

我正在尝试在 seaborn replot 图中添加两个带有标签的自定义箭头。 我尝试使用不起作用的 matplot 箭头函数,因为 seaborne relplot 是一个“facetgrid”。我在 seaborn 文档中没有看到具体的箭头指针函数。我想在两个基准的 y 值之间的特定 x 值处绘制一个箭头(例如 b1 b2)

有没有简单的方法来做到这一点? 我添加了一个简单的代码示例、数据和 2 张我尝试实现的图像。

代码:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import gc
import sys

if __name__ == '__main__':
        pfad = sys.argv[1]
        label = 'test'
        df1 = pd.read_csv(pfad, sep=';')

        sns_plot = sns.relplot(x="selectivity", ci=None, y="throughput", hue='benchmark', kind="line", data=df1,
                           dashes=False, markers=True, style="benchmark")

        sns_plot.savefig(label + ".png")
        plt.savefig(label + ".pdf", bbox_inches='tight')

        plt.show()

数据集(example.csv 在同一文件夹中)

benchmark;selectivity;throughput
b1;0.01;1426.89
b2;0.01;531.434
b1;0.03;826.89
b2;0.03;531.434
b1;0.05;626.89
b2;0.05;520.434

目前我的图表如下所示:

这就是我想要实现的:

如评论中所述,我将轴展平,从折线图中获取值,并分别添加文本注释和箭头。

if __name__ == '__main__':
    pfad = sys.argv[1]
    label = 'test'
    df1 = pd.read_csv(pfad, sep=';')

    sns_plot = sns.relplot(x="selectivity", ci=None, y="throughput", hue='benchmark', kind="line", data=df1,
                       dashes=False, markers=True, style="benchmark")
    xydata = []
    for ax in sns_plot.axes.flat:
        for li in ax.lines:
            xydata.append(li.get_xydata())
            
    ax.text(xydata[0][0][0]+0.001, (xydata[0][0][1]+xydata[1][0][1])/2, '2.5X speedup')
    ax.text(xydata[1][2][0]+0.001, (xydata[0][2][1]+xydata[1][2][1])/2, '1.3X speedup')
    ax.annotate('',
                xy=(xydata[0][0][0], xydata[0][0][1]),
                xytext=(xydata[0][0][0], xydata[1][0][1]),
                xycoords='data',
                arrowprops=dict(facecolor='black',width=2.0,headwidth=7.0,headlength=7.0,shrink=0.01))
    ax.annotate('',
                xy=(xydata[1][2][0], xydata[0][2][1]),
                xytext=(xydata[1][2][0], xydata[1][2][1]),
                xycoords='data',
                arrowprops=dict(facecolor='black',width=2.0,headwidth=7.0,headlength=7.0,shrink=0.01))
    
    #sns_plot.savefig(label + ".png")
    #plt.savefig(label + ".pdf", bbox_inches='tight')

    plt.show()