python - 分割 Seaborn fiddle 图表中的控制面

标签 python seaborn

有(如示例:https://seaborn.pydata.org/examples/grouped_violinplots.html)

sns.set(style="whitegrid", palette="pastel", color_codes=True)

# Load the example tips dataset
tips = sns.load_dataset("tips")
tips = tips[(tips['day'] == 'Sun')]
# Draw a nested violinplot and split the violins for easier comparison
sns.violinplot(x="day", y="total_bill", hue="smoker",
           split=True, inner="quart",
           palette={"Yes": "y", "No": "b"},
           data=tips)
sns.despine(left=True)

你得到:

enter image description here

是否可以控制两侧,即:向左指定“否”,向右指定"is"?

我遇到的问题是,当生成多个图时,我得到的图像在不同侧面都有数据,例如:

enter image description here

enter image description here

我希望所有图像的左侧都有“向下”,右侧有“向上”。

谢谢!

最佳答案

是的,有可能,来自官方docs

order, hue_order : lists of strings, optional
Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.

sns.violinplot(x="day", y="total_bill", hue="smoker",hue_order=['No','Yes'],
       split=True, inner="quart",
       palette={"Yes": "y", "No": "b"},
       data=tips)  

enter image description here

关于python - 分割 Seaborn fiddle 图表中的控制面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59460067/

相关文章:

python - 从 python 运行时出现 wkhtmltopdf 段错误

python - 设置 Seaborn 热图上颜色条的最大值

python - 您无法添加没有默认值的 null=False 列

python - PyMySql 更改 SQL 查询中的日期范围

python - 如何将离散值映射到 seaborn 中的热图?

python - for 循环中函数的子图

python - Seaborn 显示条形图时出错

python - 如何绘制非方形 Seaborn jointplot 或 JointGrid

Python pyopenssl 签名证书错误(Firefox : SEC_ERROR_REUSED_ISSUER_AND_SERIAL, chrome:ERR_CERT_AUTHORITY_INVALID)

python - 如何根据其他列中的条件对 pandas 的 Dataframe 列进行操作