I am trying to add two custom arrows with labels in a seaborn relplot graph. I tried using the matplot arrow function which is not working because the seaborne relplot is a “facetgrid”. I did not see a specific arrow pointer function in seaborn docu. I want to draw an arrow at a specific x value between the y values of two benchmarks (b1 b2 in example)
Is there an easy way to do this? I added a simple code example, data and 2 images of what i try to achieve.
CODE:
JavaScript
x
19
19
1
import pandas as pd
2
import seaborn as sns
3
import matplotlib.pyplot as plt
4
import gc
5
import sys
6
7
if __name__ == '__main__':
8
pfad = sys.argv[1]
9
label = 'test'
10
df1 = pd.read_csv(pfad, sep=';')
11
12
sns_plot = sns.relplot(x="selectivity", ci=None, y="throughput", hue='benchmark', kind="line", data=df1,
13
dashes=False, markers=True, style="benchmark")
14
15
sns_plot.savefig(label + ".png")
16
plt.savefig(label + ".pdf", bbox_inches='tight')
17
18
plt.show()
19
DATASET (example.csv in same folder)
JavaScript
1
8
1
benchmark;selectivity;throughput
2
b1;0.01;1426.89
3
b2;0.01;531.434
4
b1;0.03;826.89
5
b2;0.03;531.434
6
b1;0.05;626.89
7
b2;0.05;520.434
8
Currently my Graph looks like this:
This is what I want to achieve:
Advertisement
Answer
As mentioned in the comments, I flattened the axes, got the values from the line chart, and added text annotations and arrows respectively.
JavaScript
1
30
30
1
if __name__ == '__main__':
2
pfad = sys.argv[1]
3
label = 'test'
4
df1 = pd.read_csv(pfad, sep=';')
5
6
sns_plot = sns.relplot(x="selectivity", ci=None, y="throughput", hue='benchmark', kind="line", data=df1,
7
dashes=False, markers=True, style="benchmark")
8
xydata = []
9
for ax in sns_plot.axes.flat:
10
for li in ax.lines:
11
xydata.append(li.get_xydata())
12
13
ax.text(xydata[0][0][0]+0.001, (xydata[0][0][1]+xydata[1][0][1])/2, '2.5X speedup')
14
ax.text(xydata[1][2][0]+0.001, (xydata[0][2][1]+xydata[1][2][1])/2, '1.3X speedup')
15
ax.annotate('',
16
xy=(xydata[0][0][0], xydata[0][0][1]),
17
xytext=(xydata[0][0][0], xydata[1][0][1]),
18
xycoords='data',
19
arrowprops=dict(facecolor='black',width=2.0,headwidth=7.0,headlength=7.0,shrink=0.01))
20
ax.annotate('',
21
xy=(xydata[1][2][0], xydata[0][2][1]),
22
xytext=(xydata[1][2][0], xydata[1][2][1]),
23
xycoords='data',
24
arrowprops=dict(facecolor='black',width=2.0,headwidth=7.0,headlength=7.0,shrink=0.01))
25
26
#sns_plot.savefig(label + ".png")
27
#plt.savefig(label + ".pdf", bbox_inches='tight')
28
29
plt.show()
30