Dan Mintz
Dan Mintz

Reputation: 79

How do I show seaborn plots side by side from 2 different datasets?

sns.set(style="darkgrid")
parm = azdias_under_20.columns.to_series(index=None).sample(3)

for y in parm:
    sns.countplot(x=y, data=azdias_under_20)
    plt.show();
    sns.countplot(x=y, data=azdias_over_20)
    plt.show();

How do I show seaborn plots side by side from 2 different datasets? Please answer with exact details, not links to subplot or other sources.

Thank you.

    ALTERSKATEGORIE_GROB    ANREDE_KZ   CJT_GESAMTTYP   FINANZ_MINIMALIST   FINANZ_SPARER   FINANZ_VORSORGER    FINANZ_ANLEGER  FINANZ_UNAUFFAELLIGER   FINANZ_HAUSBAUER    FINANZTYP   ... PLZ8_ANTG1  PLZ8_ANTG2  PLZ8_ANTG3  PLZ8_ANTG4  PLZ8_BAUMAX PLZ8_HHZ    PLZ8_GBZ    ARBEIT  ORTSGR_KLS9 RELAT_AB
1   1.0 2   5.0 1   5   2   5   4   5   1   ... 2.0 3.0 2.0 1.0 1.0 5.0 4.0 3.0 5.0 4.0
2   3.0 2   3.0 1   4   1   2   3   5   1   ... 3.0 3.0 1.0 0.0 1.0 4.0 4.0 3.0 5.0 2.0
3   4.0 2   2.0 4   2   5   2   1   2   6   ... 2.0 2.0 2.0 0.0 1.0 3.0 4.0 2.0 3.0 3.0
4   3.0 1   5.0 4   3   4   1   3   2   5   ... 2.0 4.0 2.0 1.0 2.0 3.0 3.0 4.0 6.0 5.0
5   1.0 2   2.0 3   1   5   2   2   

Upvotes: 1

Views: 3672

Answers (2)

JohanC
JohanC

Reputation: 80509

Something like this should work:

from matplotlib import pyplot as plt
import seaborn as sns

# fill in azdias_under_20, azdias_over_20, parm, ....

# draw two plots, next to each other with the same x and y axis
for y in parm:
    fig, (ax1, ax2) = plt.subplots(figsize=(12, 6), ncols=2, sharex=True, sharey=True)
    sns.countplot(x=y, data=azdias_under_20, ax=ax1)
    sns.countplot(x=y, data=azdias_over_20, ax=ax2)
    plt.show();

Upvotes: 3

mdgr
mdgr

Reputation: 183

You can try something like this:

for indx, y in enumerate(parm):
    plt.subplot(1, len(parm), indx)
    sns.countplot(x=y, data=azdias_under_20)
plt.show()

It should plot all the sublots on a single row. I am not sure however if you can easily visualize your data this way, since the subplots will be small.

Upvotes: 0

Related Questions