简体   繁体   English

用一条线注释 seaborn swarmplot

[英]Annotating a seaborn swarmplot with a line

I have created a swarmplot and I want to add lines on the plot like so:我创建了一个 swarmplot,我想在 plot 上添加行,如下所示:

在此处输入图像描述

I want the locations of these lines to represent a value on the y-axis.我希望这些线的位置代表 y 轴上的值。 Is there a way to acheive this?有没有办法实现这一点?

You could do something like this using axhline :您可以使用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()

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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