views:

174

answers:

1

I currently have two subplots. Note: this is in matplotlib v0.99.3 on Mac OS X 10.6.x

I have an event-handler that when one of the subplots are clicked, it prints something. This is only a temporary place holder. What I want to happen is when the subplot is clicked, I want it to take up the whole figure (delete the other subplot and maximize to fill up the whole figure). How would I go about doing this?

+1  A: 

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.

tom10