Question

I have 10 subplots for which I could only use matplotlib print out 9 all in one figure as shown enter image description here

I am wondering if I could adjust my python code to allow it to fit the 10th plot?

Here is how I configured the plots so far.

fig = plt.figure(figsize=(10,8))
a1 = fig.add_subplot(331)
a2 = fig.add_subplot(332)
a3 = fig.add_subplot(333)
a4 = fig.add_subplot(334)
a5 = fig.add_subplot(335)
a6 = fig.add_subplot(336)
a7 = fig.add_subplot(337)
a8 = fig.add_subplot(338)
a9 = fig.add_subplot(339)
Was it helpful?

Solution

Just increase your plot grid:

fig = plt.figure(figsize=(10,8))
a1 = fig.add_subplot(521)
a2 = fig.add_subplot(522)
a3 = fig.add_subplot(523)
a4 = fig.add_subplot(524)
a5 = fig.add_subplot(525)
a6 = fig.add_subplot(526)
a7 = fig.add_subplot(527)
a8 = fig.add_subplot(528)
a9 = fig.add_subplot(529)
a10 = fig.add_subplot(5,2,10)

fig.add_subplot(52X) is short hand for 5 rows, by 2 columns, Xth plot. Your code only allows for 9 plots because it was a 3 x 3 grid, (fig.add_subplot(33X)); increasing it to a 5 x 2 grid allows for a 10th plot.

You can rearrange the column or row count as you please to get whatever look you desire.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top