0

I have this code:

for i in ["Dia", "DiaSemana", "Mes", "Año", "Feriado"]:
    plt.subplot(1,2,1)
    sns.boxplot(x=i, y="Y", data=df)

    plt.subplot(1,2,2)
    sns.boxplot(x=i, y="Temp", data=df)

    plt.tight_layout()
    plt.show()

It gives me all the plots I need. Here is one-time loop:

Plots

As you can see, the x axis is overlapped and I'm trying to increase the horizontal size of each plot in order to have a better visualization.

Chris
  • 2,019
  • 5
  • 22
  • 67

1 Answers1

2

You are limited by the width of your figure. You can make your figure wider with the figsize attribute. You can "grab" your figure by either explicitly defining it (plt.figure) or getting the current figure (plt.gcf).

However, I prefer is using plt.subplots to define both figure and axes:

for i in ["Dia", "DiaSemana", "Mes", "Año", "Feriado"]:
    fig, axes = plt.subplots(ncols=2, figsize=(15, 5))  # set width of figure and define both figure and axes
    sns.boxplot(x=i, y="Y", data=df, ax=axes[0])
    sns.boxplot(x=i, y="Temp", data=df, ax=axes[1])

    plt.tight_layout()
    plt.show()

Alternatively, you could decrease the number of ticks in the x axis.

busybear
  • 10,194
  • 1
  • 25
  • 42