带有连接点的群图
我尝试使用箱线图与群图以及连接数据点的线相结合来跟踪数据帧内的变化。
到目前为止,我只能使用以下代码将箱线图与群图结合起来:
import seaborn as sns
from itertools import cycle
import numpy as np
import pandas as pd
#create random dataframe with 4 conditions
df = pd.DataFrame(data = np.random.random(size=(4,4)), columns = ['A','B','C','D'])
datapoints=pd.melt(df)
#add IDs
ID = cycle(["1","2","3", "4"])
datapoints['ID'] = [next(ID) for IDs in range(len(datapoints))]
#plot values
sns.boxplot(x="variable", y="value", data=datapoints)
sns.swarmplot(x="variable", y="value", data=datapoints, color=".25")
我想要做的是跟踪每个 ID 连接 A、B、C 和 D 上的单个点的变化。
这样我就可以跟踪 ID 1 在 4 个条件下的表现。像这样的东西:
I'm try to keep track of changes within a dataframe using a boxplot
combined with a swarmplot
, and lines connecting data points.
So far I only managed to combine the boxplot with the swarmplot
, using this code:
import seaborn as sns
from itertools import cycle
import numpy as np
import pandas as pd
#create random dataframe with 4 conditions
df = pd.DataFrame(data = np.random.random(size=(4,4)), columns = ['A','B','C','D'])
datapoints=pd.melt(df)
#add IDs
ID = cycle(["1","2","3", "4"])
datapoints['ID'] = [next(ID) for IDs in range(len(datapoints))]
#plot values
sns.boxplot(x="variable", y="value", data=datapoints)
sns.swarmplot(x="variable", y="value", data=datapoints, color=".25")
Waht I would like to do is to keep track of changes connecting the single dots across A, B, C and D per ID.
This way I could follow the performance of for example ID 1 across the 4 conditions. Something like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定我是否理解这个问题,因为箱线图用于聚合信息而不是显示所有值,但如果您想显示所有点:
或:
要具有黑线,使用:
Not sure I understood the question as boxplot are used to aggregate information rather than showing all values, but if you want to show all points:
or:
To have black lines, use: