0

i am having trouble trying to figure out how to plot multiple figures in python. I have two dataframes and in each dataframe i have two columns. Hence, I want a total of 4 plots, maybe all in one row and 4 columns? or all in 2 rows and 2 columns. I tried the following trick:

    actuals = ['Acttemplow','acttemphi']
    fig,axes = plt.subplots(nrows=1,ncols=4,figsize=(12,4))
    for i,var in enumerate(actuals):
        ny_winter_dat[var].plot(ax=axes[i],title='ny winter ' + var)
        il_winter_dat[var].plot(ax=axes[i],title='illonois winter ' + var)

But upon implementing the above algo, i am getting plots of two series in two figures. and the other two figures are blank. I am not getting different series in different boxes. I tried changing nrows=2 and ncols=4 but still not able to figure it out. can someone please help? thanks

turtle_in_mind
  • 986
  • 1
  • 18
  • 36

1 Answers1

0

axes is a ndarray of shape 1,4

your loop is putting :

  • ny_winter_dat[Acttemplow] in axe #0
  • il_winter_dat[Acttemplow] in axe #0
  • ny_winter_dat[acttemphi] in axe #1
  • il_winter_dat[acttemphi] in axe #1

you want :

  • ny_winter_dat[Acttemplow] in axe #0
  • il_winter_dat[Acttemplow] in axe #2
  • ny_winter_dat[acttemphi] in axe #1
  • il_winter_dat[acttemphi] in axe #3

actuals = ['Acttemplow','acttemphi'] fig,axes = plt.subplots(nrows=1,ncols=4,figsize=(12,4)) for i,var in enumerate(actuals): ny_winter_dat[var].plot(ax=axes[i],title='ny winter ' + var) il_winter_dat[var].plot(ax=axes[i+2],title='illonois winter ' + var)

euri10
  • 2,446
  • 3
  • 24
  • 46