How do I grow the size of a figure in matplotlib, to accommodate a variable number of subplots, while keeping the heights constant?
I'm plotting a large number of figures, which each consists of a main subplot (green) which should cover 90% of the height of the image. Added to that, I'm adding a variable number of annotation subplots (orange) which should each take up 10% height. In other words, the base case of a figure with one annotation would result in a figure of height 100%, and a figure with 5 annotations would have a total height of 140%
A command that allows me to plot the main plot then grow the figure as I add each subplot would be ideal.
Practical Data Science using Python Make a list of data points and colors. Plot the bars with data and colors, using bar() method. Using FuncAnimation() class, make an animation by repeatedly calling a function, animation, that sets the height of the bar and facecolor of the bars.
The tight_layout() function in pyplot module of matplotlib library is used to automatically adjust subplot parameters to give specified padding.
cla() Function. The cla() function in pyplot module of matplotlib library is used to clear the current axes. Syntax: matplotlib.pyplot.cla()
I don't think this is an automatic option. I could be wrong. There is figure.set_figheight
which adjusts the size in inches. The problem is that the axes are defined relative to the figure dimensions, so any subplots on the figure before you resize are scaled to fill in the extra 40% space.
You would have to write a routine that both adjusts the height of the figure and scale and displace anything in the figure. Not impossible to do, but again I don't think this feature exists yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With