1
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   
Dan Mintz
  • 49
  • 2
  • 9
  • If you write "Please answer with exact details" you might consider giving more details about how the `azdias_under_20` dataframe looks like. Preferably constructing some random demo data. If you don't provide the necessary [details](https://stackoverflow.com/help/minimal-reproducible-example), why do you expect somebody can give a detailed answer? Also, you seem to be drawing 6 plots and ask about 2 side by side – JohanC Jan 18 '20 at 15:55
  • You are right. I tried to expand and detail my question. there are two data sets. look very similar like the one above. Need to show each plot from each dataset side by side. Thank you. – Dan Mintz Jan 18 '20 at 16:24
  • It is still extremely unclear what you want. Two plot, one next to the other? Under each other? With the same x and y axis? – JohanC Jan 18 '20 at 17:00
  • Two plots, one next to the other. Same x and y axis. I am comparing the same column from 2 different datasets – Dan Mintz Jan 18 '20 at 17:01

2 Answers2

3

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();
JohanC
  • 71,591
  • 8
  • 33
  • 66
0

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.

mdgr
  • 173
  • 9
  • Or you can check out this question if you want to find out how to format your plots individually: https://stackoverflow.com/questions/25239933/how-to-add-title-to-subplots-in-matplotlib – mdgr Jan 18 '20 at 14:18
  • is there any error showing, or it just doesn't do anything? – mdgr Jan 18 '20 at 15:29