0

I have this code that takes my dataframe and creates a subplot for each year in the "year" column with the x-axis values from the "Values" column:

ax = sns.displot(
    data=df, x='Values', col="Year",
    kind="hist", height=4, aspect=.7,
)

ax.set(xlabel = None, ylabel='Frequency')

ax.set_titles('{col_name}')

This creates a 1x4 set of histograms, one for each year in my dataset.

What I am trying to figure out is how to turn this 1x4 set into a 2x2 set of subplots.

I tried the following:

axes = plt.subplots(2,2)

ax = sns.displot(
    data=df, x='Values', col="Year",
    kind="hist", height=4, aspect=.7, ax=axes
)

ax.set(xlabel = None, ylabel='Frequency')

ax.set_titles('{col_name}')

But what this did was produce a blank 2x2 set of plots, and then underneath that produce my original 1x4 set of plots with my data plotted. How can I modify my code so that I can produce my 2x2 set of histograms?

BigBen
  • 38,994
  • 6
  • 24
  • 37

0 Answers0