0

I need to plot 5 tracks (basically 4 as two share one track), and each track is a column among many columns of my dataframe. I need to use matplotlib and subplots but since I first need to tell subplots I have 5 tracks, it would create an empty track in between my 4 tracks. If I enter 4 subplots at the beginning, it says: ValueError: not enough values to unpack (expected 5, got 4)

here are the two situations:

ax[1],ax[2] will share the same x axis (they basically need to be on the same track).

fig, [ax[0],ax[1],ax[2],ax[3],ax[4]]  = plt.subplots(1, 5, figsize = (15, 30), sharey = True, dpi=300)

In this case, I will have an empty track in between my tracks, and if I put 4 subplots:

fig, [ax[0],ax[1],ax[2],ax[3],ax[4]]  = plt.subplots(1, 4, figsize = (15, 30), sharey = True, dpi=300)

it will throw me an error: "ValueError: not enough values to unpack (expected 5, got 4)"

Any way to deal with this?

JohanC
  • 59,187
  • 8
  • 19
  • 45
Skylimit
  • 11
  • 2
  • `plt.subplots(1, 4, ...)` creates 4 subplots. `[ax[0],ax[1],ax[2],ax[3],ax[4]]` would be 5 subplots. `sharey=True` doesn't create a new subplot; a shared y-axis means the limits (smallest and largest y visible on the subplot) will be the same for all subplots. – JohanC Nov 07 '21 at 22:34

0 Answers0