Search code examples
pythonmatplotlibpositionaxisfigure

Matplotlib - User changes amount of subplots


In my code the user should be able to change the amount of subplots in the figure. So first there are two subplots:

enter image description here

I use following code:

ax1 = figure.add_sublots(2,1,1)
ax2 = figure.add_sublots(2,1,2)

If the plus button is pressed one subplot shall be added:

enter image description here

How should I do this? Is there a command like

ax1.change_subplot(3,1,1)
ax2.change_subplot(3,1,2)
ax3 = figure.add_sublots(3,1,3)

or do I have to delete all subplots and redraw them (which I would like to avoid)?


Solution

  • The command I was looking for is:

    ax1.change_geometry(3,1,1)
    

    With this command it is possible to rearrange the sublots. I found this solution here: Dynamically add subplots in matplotlib with more than one column