Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically grow a figure in matplotlib

Illustration

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.

like image 241
pufferfish Avatar asked May 24 '12 20:05

pufferfish


People also ask

How do you make a dynamic plot in Python?

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.

What is PLT Tight_layout ()?

The tight_layout() function in pyplot module of matplotlib library is used to automatically adjust subplot parameters to give specified padding.

What is PLT CLA ()?

cla() Function. The cla() function in pyplot module of matplotlib library is used to clear the current axes. Syntax: matplotlib.pyplot.cla()


1 Answers

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.

like image 193
Yann Avatar answered Sep 18 '22 03:09

Yann