188188import mlab #so I can override hist, psd, etc...
189189
190190from axes import Axes , PolarAxes
191+ import backends
191192from backends import new_figure_manager , error_msg , \
192193 draw_if_interactive , show
193194
@@ -758,7 +759,7 @@ def figlegend(handles, labels, loc, **kwargs):
758759 return l
759760
760761
761- def figure (num = 1 ,
762+ def figure (num = None , # autoincrement if None, else integer from 1-N
762763 figsize = None , # defaults to rc figure.figsize
763764 dpi = None , # defaults to rc figure.dpi
764765 facecolor = None , # defaults to rc figure.facecolor
@@ -776,6 +777,9 @@ def figure(num=1,
776777
777778 figure(1)
778779
780+ If num=None, the figure number will be incremented and a new
781+ figure will be created.
782+
779783 figsize - width in height x inches; defaults to rc figure.figsize
780784 dpi - resolution; defaults to rc figure.dpi
781785 facecolor - the background color; defaults to rc figure.facecolor
@@ -794,6 +798,15 @@ def figure(num=1,
794798 if num == 0 :
795799 error_msg ('Figure number can not be 0.\n ' + \
796800 'Hey, give me a break, this is matlab(TM) compatability' )
801+ return
802+
803+
804+ if num is None :
805+ allnums = [f .num for f in _pylab_helpers .Gcf .get_all_fig_managers ()]
806+ if allnums :
807+ num = max (allnums ) + 1
808+ else :
809+ num = 1
797810
798811 figManager = _pylab_helpers .Gcf .get_fig_manager (num )
799812 if figManager is None :
@@ -1585,6 +1598,16 @@ def ion():
15851598 'turn interactive mode on'
15861599 matplotlib .interactive (True )
15871600
1601+
1602+ def switch_backend (newbackend ):
1603+ close ('all' )
1604+ global new_figure_manager , error_msg , draw_if_interactive , show
1605+ matplotlib .use (newbackend )
1606+ reload (backends )
1607+ from backends import new_figure_manager , error_msg , \
1608+ draw_if_interactive , show
1609+
1610+
15881611### The following functions were autogenerated by the boilerplate.py
15891612### script. They are simple wrappers around the Axes methods of the
15901613### same name
@@ -2528,7 +2551,7 @@ def winter():
25282551 'Line2D' , 'Polygon' , 'Rectangle' , 'Circle' , 'Text' , 'cm' ,
25292552 'get_cmap' , 'normalize' ,
25302553
2531- 'show' , 'rcParams'
2554+ 'show' , 'rcParams' , 'switch_backend'
25322555 ]
25332556
25342557
0 commit comments