繁体   English   中英

将均值和标准差添加到联合图边距

[英]Adding mean and std to jointplot margins

我有一个 seaborn.jointplot 与我附上的图非常相似(来自 seaborn 图库)。 但是,我想知道是否可以在每个边际图上添加一条彩色线来标记均值,并在其周围的一个标准偏差的区间内添加一个范围标记。 我喜欢海图人物的整体设计,但我有点需要那条额外的信息。

Seaborn 联合图

生成附加 plot 的库中的代码:

import seaborn as sns
sns.set_theme(style="darkgrid")

tips = sns.load_dataset("tips")
g = sns.jointplot(x="total_bill", y="tip", data=tips,
                  kind="reg", truncate=False,
                  xlim=(0, 60), ylim=(0, 12),
                  color="m", height=7)

我使用此答案制作的内容:

先自己试试

您可以在关节轴和边缘轴上绘制线条,如本文中的示例所示

这是显示均值和标准差的示例方法。 许多备选方案是可能的。

from matplotlib import pyplot as plt
import seaborn as sns

sns.set_theme(style="darkgrid")
tips = sns.load_dataset("tips")
g = sns.jointplot(x="total_bill", y="tip", data=tips,
                  kind="reg", truncate=False,
                  xlim=(0, 60), ylim=(0, 12),
                  color="m", height=7)

x_mean = tips["total_bill"].mean()
x_std = tips["total_bill"].std()
g.ax_marg_x.axvspan(x_mean - x_std, x_mean + x_std, color='red', alpha=0.1)

y_mean = tips["tip"].mean()
y_std = tips["tip"].std()
g.ax_marg_y.axhspan(y_mean - y_std, y_mean + y_std, color='red', alpha=0.1)

g.refline(x=x_mean, y=y_mean, color='red', ls='--')

plt.show()

带有均值和 sdev 的 sns.jointplot

PS:评论中提到refline()可以用来替换这四行:

for ax in [g.ax_joint, g.ax_marg_x]:
    ax.axvline(x_mean, color='red', ls='--')
for ax in [g.ax_joint, g.ax_marg_y]:
    ax.axhline(y_mean, color='red', ls='--')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM