@@ -16,6 +16,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name
1616from matplotlib .numerix import asarray , fromstring , UInt8 , zeros , \
1717 where , transpose , nonzero , indices , ones , nx
1818import matplotlib .numerix as numerix
19+ from matplotlib .widgets import SubplotTool
1920
2021from backend_gdk import RendererGDK
2122
@@ -404,15 +405,8 @@ def __init__(self, canvas, num):
404405 self .canvas .show ()
405406 self .vbox .pack_start (self .canvas , True , True )
406407
407- # must be inited after the window, drawingArea and figure
408- # attrs are set
409- if matplotlib .rcParams ['toolbar' ]== 'classic' :
410- self .toolbar = NavigationToolbar (canvas , self .window )
411- elif matplotlib .rcParams ['toolbar' ]== 'toolbar2' :
412- self .toolbar = NavigationToolbar2GTK (canvas , self .window )
413- else :
414- self .toolbar = None
415-
408+ self .toolbar = self ._get_toolbar (canvas )
409+
416410 # calculate size for window
417411 w = int (self .canvas .figure .bbox .width ())
418412 h = int (self .canvas .figure .bbox .height ())
@@ -444,6 +438,17 @@ def destroy(self, *args):
444438 if Gcf .get_num_fig_managers ()== 0 and not matplotlib .is_interactive ():
445439 gtk .main_quit ()
446440
441+ def _get_toolbar (self , canvas ):
442+ # must be inited after the window, drawingArea and figure
443+ # attrs are set
444+ if matplotlib .rcParams ['toolbar' ]== 'classic' :
445+ toolbar = NavigationToolbar (canvas , self .window )
446+ elif matplotlib .rcParams ['toolbar' ]== 'toolbar2' :
447+ toolbar = NavigationToolbar2GTK (canvas , self .window )
448+ else :
449+ toolbar = None
450+ return toolbar
451+
447452
448453
449454class NavigationToolbar2GTK (NavigationToolbar2 , gtk .Toolbar ):
@@ -456,6 +461,7 @@ class NavigationToolbar2GTK(NavigationToolbar2, gtk.Toolbar):
456461 ('Pan' , 'Pan axes with left mouse, zoom with right' , 'move.png' ,'pan' ),
457462 ('Zoom' , 'Zoom to rectangle' ,'zoom_to_rect.png' , 'zoom' ),
458463 (None , None , None , None ),
464+ ('Subplots' , 'Configure subplots' ,'subplots.png' , 'configure_subplots' ),
459465 ('Save' , 'Save the figure' ,'filesave.png' , 'save_figure' ),
460466 )
461467
@@ -594,6 +600,30 @@ def save_figure(self, button):
594600 fname = self .fileselect .get_filename_from_user ()
595601 if fname :
596602 self .canvas .print_figure (fname )
603+
604+ def configure_subplots (self , button ):
605+ toolfig = Figure (figsize = (6 ,3 ))
606+ canvas = self ._get_canvas (toolfig )
607+ toolfig .subplots_adjust (top = 0.9 )
608+ tool = SubplotTool (self .canvas .figure , toolfig )
609+
610+ w = int (toolfig .bbox .width ())
611+ h = int (toolfig .bbox .height ())
612+
613+
614+ window = gtk .Window ()
615+ window .set_title ("Subplot Configuration Tool" )
616+ window .set_default_size (w , h )
617+ vbox = gtk .VBox ()
618+ window .add (vbox )
619+ vbox .show ()
620+
621+ canvas .show ()
622+ vbox .pack_start (canvas , True , True )
623+ window .show ()
624+
625+ def _get_canvas (self , fig ):
626+ return FigureCanvasGTK (fig )
597627
598628
599629class NavigationToolbar (gtk .Toolbar ):
0 commit comments