【问题标题】:Seaborn swarmplot and pointplot dodge alignmentSeaborn swarmplot 和 pointplot 闪避对齐
【发布时间】:2020-07-21 01:07:15
【问题描述】:

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

这是我的代码:

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

这是我的情节:

【问题讨论】:

    标签: plot seaborn swarmplot


    【解决方案1】:

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

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

    【讨论】:

    • swarmplot 的 dodge 参数是纯布尔值。传递浮点值不会影响绘图行为。奇怪的是,传递浮点数不会引发错误,而是将任何不同于“False”或“0”的值解释为 True。请参阅seaborn.pydata.org/generated/seaborn.swarmplot.html 请注意,与 swarmplot 不同,pointplot dodge 参数确实接受布尔值浮点值。
    猜你喜欢
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    • 2018-02-01
    • 2017-03-03
    • 2017-10-03
    • 2021-11-04
    • 2021-05-01
    • 1970-01-01
    相关资源
    最近更新 更多