-1

I have the following code which works just fine:

plt.rcParams["figure.figsize"] = (5,5)  # V1.0b
fig, axes = plt.subplots(ncols = 2, nrows = 2)  # V1.0b
ax1, ax2, ax3, ax4 = axes.flatten()
plt.subplot(2, 2, 1)
ax1.plot(x1, y1)
ax1.plot(x2, y2)
(etc)

Exactly as expected, I get 2 plots in row 1, 2 plots in row 2.

Now, I want 2 rows by 3 cols and 4 plots (from exactly the same data):

plt.rcParams["figure.figsize"] = (6,4)
fig, axes = plt.subplots(ncols = 3, nrows = 2) 
ax1, ax2, ax3, ax4 = axes.flatten()
plt.subplot(2, 3, 1)
ax1.plot(x1, y1)
(etc)

And I get an error from the line:

---> 12 ax1, ax2, ax3, ax4 = axes.flatten()

The error message is:

ValueError: too many values to unpack (expected 4)

Surely ax1, ax2, ax3, ax4 are the 4 values? But, evidently not; what's going wrong here?

1 Answers1

0

I've found this works. As you say, no need for subplots:

figure, axis = plt.subplots(3, 3)

axis[0, 0]
axis[0, 0].set_title("NGC0628")
axis[0, 0].plot(x0,y0)

axis[0, 1]
axis[0, 0].plot(x1,y1)

axis[0, 2]
axis[0, 0].plot(x2,y2)

(etc)

BTW I need control over each plot, i.e. as in

axis[0, 0].set_title("NGC0628")

Thanks for the steer