close

How can I overlay two graphs in Seaborn?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How can I overlay two graphs in Seaborn in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How can I overlay two graphs in Seaborn?

  1. How can I overlay two graphs in Seaborn?

    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

  2. overlay two graphs in Seaborn

    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

Method 1

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)

Method 2

One solution is to introduce a secondary axis:

    fig, ax = plt.subplots()
    sb.regplot(x='round', y='money', data=firm, ax=ax)
    ax2 = ax.twinx()
    sb.regplot(x='round', y='dead', data=firm, ax=ax2, color='r')
    sb.plt.show()
enter image description here

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read