Seaborn swarmplot and pointplot dodge alignment

一世执手 提交于 2020-06-01 08:16:38

问题


I am plotting this:

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()

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


回答1:


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) 


来源:https://stackoverflow.com/questions/54272277/seaborn-swarmplot-and-pointplot-dodge-alignment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!