如何在 Seaborn 中叠加两个图形? [英] How can I overlay two graphs in Seaborn?

查看:609
本文介绍了如何在 Seaborn 中叠加两个图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Seaborn 中叠加两个图形?我的数据中有两列我希望将它们放在同一个图表中.我如何才能保留两个图的标签.

How can I overlay two graphs in Seaborn? I have two columns in my data I would like to have them in the same graph. How can I do it preserving the labeling for both graphs.

推荐答案

在单个 Axes 上操作的 seaborn 函数可以将一个 Axes 作为参数.

seaborn function that operate on a single Axes can take one as an argument.

例如,seaborn.kdeplot 的文档 包括:

For instance, the docs to seaborn.kdeplot include:

ax : matplotlib axis, optional
    Axis to plot on, otherwise uses current axis

如果你这样做了:

df = function_to_load_my_data()
fig, ax = plt.subplots()

然后你可以这样做:

seaborn.kdeplot(df['col1'], ax=ax)
seaborn.kdeplot(df['col2'], ax=ax)

这篇关于如何在 Seaborn 中叠加两个图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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