0
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(14, 10))

produces the below, which is expected and makes sense.

enter image description here

However, following the same format and basic intuition, if I change the code to:

fig, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(3, 3, figsize=(14, 10))

I get an: ValueError: too many values to unpack (expected 2). I get the same error if I leave it as fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(3, 3, figsize=(14, 10)). Why is this?

Also if someone has an intuitive guide for the subplots library written for beginners, it would be very helpful because I am not finding the documentation intuitive at all.

Katsu
  • 8,479
  • 3
  • 15
  • 16
  • 3
    Wouldn't 3 times 3 be 9? That seems quite intuitive. `fig, ((ax1, ax2, ax3), (ax4, ax5, ax6), (ax7, ax8, ax9)) = ...`. Or maybe you only want 2 rows instead of 3 as in `plt.subplots(nrows=2, ncols=3, figsize=...)`? – JohanC Feb 16 '23 at 23:15
  • Thank you. Thrown off by the error because it said I had too many values when I hadn't even given it the 3rd row of `(ax7, ax8, ax9)`. – Katsu Feb 16 '23 at 23:17
  • 2
    The error comes from Python, not matplotlib. `plt.subplots(3,3)` returns a figure and 3 rows (each of 3 subplots), and you try to assign those 3 rows to only 2 spots. – JohanC Feb 16 '23 at 23:19
  • Do you know of any good tutorials for the `subplot` package that is written for beginners? Documentation is a bit too dense for me. – Katsu Feb 16 '23 at 23:20
  • The easiest to me would be following along with examples such as [these](https://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html). But they assume you know your way around in Python, and know the basic tricks of numpy. If you need something special, there usually are StackOverflow questions that contain similar examples that you can copy and adapt. – JohanC Feb 16 '23 at 23:24

0 Answers0