You can do this by modifying the axes that subplot returns. That is, axes can be positioned and sized in any desired way, and subplot is just a function that returns axes positioned in a uniform grid; but once you have these axes from subplot you can arbitrarily resize and reposition them. Here's an example:
from pylab import *
axes = [None, None]
def make():
figure()
axes[0] = subplot(1, 2, 1)
axes[1] = subplot(1, 2, 2)
show()
def re_form():
xmax = axes[1].get_position().get_points()[1][0]
axes[1].set_axis_off()
(x0, y0), (x1, y1) = axes[0].get_position().get_points() # xmin, ymin, xmax, ymax
axes[0].set_position([x0, y0, xmax-x0, y1-y0]) # x, y, width, height
show()
Here I used show()
to update the plot, but you'll want to use something more appropriate for your event handler. This demo works with iPython: first run
the file, then call make()
, which draws the two axes, and then re_form()
, which removes the second axis and widens the first.