Is there a matplotlib function in Python for forcing all subplots inside different figures to have the same x and y axis length?

Question:

I’m testing out different way of displaying figures. I have one figure which is made up of 12 subplots split into two columns. Something like…

fig, ax = plt.subplots(6, 2, figsize= (20,26))

I have another code which splits the 12 subplots into 3 different figures based on categorical data. Something like

figA, ax = plt.subplots(5, 1, figsize= (10,23))
figB, ax = plt.subplots(3, 1, figsize= (10,17))
fig2, ax = plt.subplots(4, 1, figsize= (10,20))

Is there a way to ensure all the subplots in every figure have the same x and y axis length?

Asked By: Bojan Milinic

||

Answers:

Answer turns out to be simple. Use a variable that can be scaled by the number of plots in the figure. So, a figure with more plots will have a higher figsize yet equal plot sizes. Something like…

ps = 5 #indicates plot size
figA, ax = plt.subplots(5, 1, figsize= (10, 5*ps))
figB, ax = plt.subplots(3, 1, figsize= (10, 3*ps))
fig2, ax = plt.subplots(4, 1, figsize= (10, 4*ps))
Answered By: Bojan Milinic

I had a similar problem, try avg(len(x)) as the multiplier. It scales suitably for all lengths.

Answered By: Immature trader