How can I overlay two graphs in Seaborn?

后端 未结 4 1942
梦谈多话
梦谈多话 2020-11-27 17:59

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.

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 18:39

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

    For instance, the docs to seaborn.kdeplot include:

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

    So if you did:

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

    You could then do:

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

提交回复
热议问题