mpl event backend; replotting a subplot (inefficient example improvement suggestions?)

I want to create an copy of a subplot in its unique figure after being clicked on in a figure with multiple subplots. My code seems to work but I believe is inefficient and I’d like to understand how to use the event.* information more effectively in mpl.

I am successfully creating multiple subplots in a Figure using a class with lines for the data such as below. I create a new figure for each instance of the class with 8 subplots in each.


Furthermore I am using a mpl_connect to successfully capture and then validate which instance of the Figure for each of the unique subplots clicked on.

self.cid=self.canvas.mpl_connect(‘button_press_event’, click)

I want to use the event to make an alternate sized plot of the subplot chosen. I can do this through some modest logic where I use the event information identify the instance clicked on. A partial description of this logic is below - which seems to work properly. (a, b, c … are subplots; Instances are Kfigure, Yfigure etc…)

def click(event):
print ‘you clicked x,y’, event.x, event.y
print ‘you clicked inaxes’, event.inaxes
print ‘string name of event’,
print ‘figure canvas instance’, event.canvas
if event.canvas==Kfigure.canvas:
print “K canvas clicked”
if event.canvas==Yfigure.canvas:
print “Y canvas clicked”
if event.inaxes==Kfigure.a:
print “clicked inside subplot a of figure K”

However, to create an alternate “new” plot of the subplot I clicked, I have to create extended logic code (as above) for each of 40 subplots on 5 figures, and then reidentify the source data similar to the original exec line and shown below. This seems inefficient. Isn’t there a more straightforward way to create the subplot clicked in its instances of “new” figure // sorry if my terminology is inexact… noob // A section of my suspected inefficient code is below.

Isn’t there a way to use the event.inaxes, or other axes or data information to identify the data to be plotted and then subplot it? Ideally this should include legend information that was created with the instance as well - that is not explicitly shown but I have done. All I am really trying to do is enlarge one of the subplots for the user. In the example in this email, I simply want to have a large Kfigure.a created.

I can get my code to work but it seems overly long and inefficient.

if event.inaxes==Kfigure.a:
print “clicked inside subplot a of figure K”
bigroot.wm_title(“title with big wm_title”)
bigf=Figure(figsize=(3,6), dpi=72)
bigcanvas=FigureCanvasTkAgg(bigf, master=bigroot)


Looking for last minute shopping deals?
Find them fast with Yahoo! Search.