简体   繁体   中英

Annotating a seaborn swarmplot with a line

I have created a swarmplot and I want to add lines on the plot like so:

在此处输入图像描述

I want the locations of these lines to represent a value on the y-axis. Is there a way to acheive this?

You could do something like this using axhline :

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

dataset = {
    'A': [23,53,23,52,52,78],
    'B': [45,78,68,68,79,79],
    'C': [3,46,24,57,76,13]
}

df = pd.DataFrame(dataset)

graph = sns.swarmplot(x="variable", y="value", data=df.melt())
graph.axhline(50, xmin=0.065, xmax=0.265)
graph.axhline(30, xmin=0.40, xmax=0.60)
graph.axhline(70, xmin=0.735, xmax=0.935)
plt.show()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM