figure.subplot not adding axis after deleting axis

Hi all,

I am creating a GUI using wxPython and Matplotlib. In it, I am trying to delete an axis in a figure and then adding another axis to the same figure. In essence, I am attempting to dynamically update the figure. I am using pylab.figure.

I am using the figure.delaxes function to delete the desired axes. That works fine. I am then changing the geometry of the rest of the axes to update the display. Afterwards, I am trying to append a new axes to the end after updating the other axes (once again using change_geometry).

Pseudocode:

  • delete the selected axis using figure.delaxes(axis)

  • update the rest of the axes using change_geometry

  • when it is time to add a new axis

-update the current axes using change_geometry

-add a subplot to the end

This approach works fine if the axes that was deleted was the axis on the end (the last one). If the deleted axis was in the middle or beginning then the figure.add_subplot(…) does not add an axis to the figure. Instead, it returns the previous axis. So if there were two axes left when one axis in the middle was deleted, ie. [axis1, axis2], figure.add_subplot would return axis2 and so the axes list would still be [axis1, axis2]

This occurs both in the GUI and when run interactively via PyCrust.

Any thoughts on to why this would happen?

python 2.7

matplotlib version: 1.1.0

OS X 10.6.8