Programmatically grow a shape in matplotlib

Illustration

How to increase the size of a figure in matplotlib to accommodate a variable number of subheadings while maintaining a constant height?

I draw a large number of numbers, each of which consists of a main subtitle (green), which should cover 90% of the image height. In addition, I add a variable number of annotation subtitles (orange), each of which should occupy 10% of the height. In other words, the base case of a figure with one annotation will result in a figure 100% high, and a figure with 5 annotations will have a total height of 140%

The command that allows me to display the main graph, then enlarge the figure, as I add that every subplot would be perfect.

+6
source share
2 answers

I do not think this is an automatic option. I could be wrong. There is a figure.set_figheight that adjusts the size in inches. The problem is that the axes are relative to the size of the shape, so any subheadings in the shape are scaled before resizing to fill an additional 40% of the space.

You will need to write a procedure that adjusts the height of the shape and scale and supplants something in the drawing. It is impossible to do, but again I do not think that this function exists.

+1
source
 br@ymir :~/temp$ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib.pyplot as plt >>> fig=plt.figure() >>> fig.get_size_inches() array([ 8., 6.]) >>> fig.set_size_inches([8.,12.]) >>> ax=fig.add_subplot(111) >>> ax.plot([1,1,2],[3,4,5],'ro-') [<matplotlib.lines.Line2D object at 0x2428590>] >>> ax1 = fig.add_subplot(212) >>> ax1.plot([2,3,4],[8,9,11],'bs-') [<matplotlib.lines.Line2D object at 0x2461450>] >>> fig.subplots_adjust() 

produces enter image description here

and you can easily customize it further.

0
source

Source: https://habr.com/ru/post/916606/