Seaborn swarmplot 和 pointplot 闪避对齐 [英] Seaborn swarmplot and pointplot dodge alignment

查看:58
本文介绍了Seaborn swarmplot 和 pointplot 闪避对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将点图的均值 + SEM 与相应的群图对齐?

Is there a way to align the mean+SEM of a pointplot and the corresponding swarmplot?

这是我的代码:

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

fig, ax = plt.subplots(nrows=1, ncols=1)
n=200
to_plot = np.random.uniform(low=0.0, high=1.0, size=n)
mods = ['a','b']
model_col = mods*(n/2)
opt=['1']*(n/2)+['2']*(n/2)

d={'Model':pd.Series(model_col),'Par':pd.Series(to_plot),'opt':pd.Series(opt)}
df = pd.DataFrame(d)
sns.swarmplot(x='Model', y='Par',hue='opt',dodge=True,data=df,size=2,palette=['#469990','#000075'])
sns.pointplot(x="Model", y="Par", hue='opt', data=df,join=False,dodge=True,
     ci=68,n_boot=1000,capsize=0.1,errwidth=0.5,scale = 1.5,palette=['k','k'])

ax.get_legend().remove()
plt.show()

这是我的情节:

推荐答案

swarmplotpointplot 似乎为各自的 dodge 使用了不同的默认值参数.但是,您可以将它们设置为相等的值,例如

It seems swarmplot and pointplot use different defaults for their respective dodge paramter. However you may set them to equal values, e.g.

sns.swarmplot(...,  dodge=0.4) 
sns.pointplot(...,  dodge=0.4) 

这篇关于Seaborn swarmplot 和 pointplot 闪避对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆