6464 MaxNLocator
6565from matplotlib .backends import pylab_setup
6666
67+
6768## Backend detection ##
69+
6870def _backend_selection ():
6971 """ If rcParams['backend_fallback'] is true, check to see if the
7072 current backend is compatible with the current running event
@@ -74,7 +76,7 @@ def _backend_selection():
7476 if not rcParams ['backend_fallback' ] or backend not in _interactive_bk :
7577 return
7678 is_agg_backend = rcParams ['backend' ].endswith ('Agg' )
77- if 'wx' in sys .modules and not backend in ('WX' , 'WXAgg' ):
79+ if 'wx' in sys .modules and backend not in ('WX' , 'WXAgg' ):
7880 import wx
7981 if wx .App .IsMainLoopRunning ():
8082 rcParams ['backend' ] = 'wx' + 'Agg' * is_agg_backend
@@ -224,7 +226,8 @@ def switch_backend(newbackend):
224226 global _backend_mod , new_figure_manager , draw_if_interactive , _show
225227 matplotlib .use (newbackend , warn = False , force = True )
226228 from matplotlib .backends import pylab_setup
227- _backend_mod , new_figure_manager , draw_if_interactive , _show = pylab_setup ()
229+ _backend_mod , new_figure_manager , draw_if_interactive , _show = \
230+ pylab_setup ()
228231
229232
230233def show (* args , ** kw ):
@@ -284,10 +287,8 @@ def pause(interval):
284287 else :
285288 time .sleep (interval )
286289
287-
288290## Any Artist ##
289291
290-
291292def xkcd (scale = 1 , length = 100 , randomness = 2 ):
292293 """
293294 Turns on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
@@ -360,7 +361,6 @@ def __enter__(self):
360361
361362 return dummy_ctx ()
362363
363-
364364## Figures ##
365365
366366def figure (num = None , # autoincrement if None, else integer from 1-N
@@ -604,10 +604,8 @@ def close(*args):
604604 else :
605605 raise TypeError ('close takes 0 or 1 arguments' )
606606
607-
608607## Axes ##
609608
610-
611609def axes (arg = None , ** kwargs ):
612610 """
613611 Add an axes to the current figure and make it the current axes.
@@ -739,12 +737,13 @@ def subplot(*args, **kwargs):
739737 import matplotlib.pyplot as plt
740738 # plot a line, implicitly creating a subplot(111)
741739 plt.plot([1,2,3])
742- # now create a subplot which represents the top plot of a grid
743- # with 2 rows and 1 column. Since this subplot will overlap the
744- # first, the plot (and its axes) previously created, will be removed
740+ # now create a subplot which represents the top plot of a grid with
741+ # 2 rows and 1 column. Since this subplot will overlap the first, the
742+ # plot (and its axes) previously created, will be removed
745743 plt.subplot(211)
746744 plt.plot(range(12))
747- plt.subplot(212, facecolor='y') # creates 2nd subplot with yellow background
745+ # create a second subplot with yellow background
746+ plt.subplot(212, facecolor='y')
748747
749748 If you do not want this behavior, use the
750749 :meth:`~matplotlib.figure.Figure.add_subplot` method or the
@@ -781,28 +780,26 @@ def subplot(*args, **kwargs):
781780
782781 """
783782 # if subplot called without arguments, create subplot(1,1,1)
784- if len (args )== 0 :
785- args = (1 ,1 , 1 )
783+ if len (args ) == 0 :
784+ args = (1 , 1 , 1 )
786785
787786 # This check was added because it is very easy to type
788787 # subplot(1, 2, False) when subplots(1, 2, False) was intended
789788 # (sharex=False, that is). In most cases, no error will
790789 # ever occur, but mysterious behavior can result because what was
791790 # intended to be the sharex argument is instead treated as a
792791 # subplot index for subplot()
793- if len (args ) >= 3 and isinstance (args [2 ], bool ) :
794- warnings .warn ("The subplot index argument to subplot() appears"
795- " to be a boolean. Did you intend to use subplots()?" )
792+ if len (args ) >= 3 and isinstance (args [2 ], bool ):
793+ warnings .warn ("The subplot index argument to subplot() appears "
794+ "to be a boolean. Did you intend to use subplots()?" )
796795
797796 fig = gcf ()
798797 a = fig .add_subplot (* args , ** kwargs )
799798 bbox = a .bbox
800- byebye = []
801- for other in fig .axes :
802- if other == a : continue
803- if bbox .fully_overlaps (other .bbox ):
804- byebye .append (other )
805- for ax in byebye : delaxes (ax )
799+ byebye = [other for other in fig .axes
800+ if other is not a and bbox .fully_overlaps (other .bbox )]
801+ for ax in byebye :
802+ delaxes (ax )
806803
807804 return a
808805
@@ -1024,24 +1021,28 @@ def subplot_tool(targetfig=None):
10241021 """
10251022 Launch a subplot tool window for a figure.
10261023
1027- A :class:`matplotlib.widgets.SubplotTool` instance is returned.
1024+ Returns
1025+ -------
1026+ `matplotlib.widgets.SubplotTool`
10281027 """
1029- tbar = rcParams [' toolbar' ] # turn off the navigation toolbar for the toolfig
1030- rcParams [' toolbar' ] = ' None'
1028+ tbar = rcParams [" toolbar" ] # Turn off the nav toolbar for the toolfig.
1029+ rcParams [" toolbar" ] = " None"
10311030 if targetfig is None :
10321031 manager = get_current_fig_manager ()
10331032 targetfig = manager .canvas .figure
10341033 else :
1035- # find the manager for this figure
1034+ # Find the manager for this figure.
10361035 for manager in _pylab_helpers .Gcf ._activeQue :
1037- if manager .canvas .figure == targetfig : break
1038- else : raise RuntimeError ('Could not find manager for targetfig' )
1036+ if manager .canvas .figure == targetfig :
1037+ break
1038+ else :
1039+ raise RuntimeError ("Could not find manager for targetfig" )
10391040
1040- toolfig = figure (figsize = (6 ,3 ))
1041+ toolfig = figure (figsize = (6 , 3 ))
10411042 toolfig .subplots_adjust (top = 0.9 )
1042- ret = SubplotTool (targetfig , toolfig )
1043- rcParams [' toolbar' ] = tbar
1044- _pylab_helpers .Gcf .set_active (manager ) # restore the current figure
1043+ ret = SubplotTool (targetfig , toolfig )
1044+ rcParams [" toolbar" ] = tbar
1045+ _pylab_helpers .Gcf .set_active (manager ) # Restore the current figure.
10451046 return ret
10461047
10471048
@@ -1058,10 +1059,8 @@ def box(on=None):
10581059 on = not ax .get_frame_on ()
10591060 ax .set_frame_on (on )
10601061
1061-
10621062## Axis ##
10631063
1064-
10651064def xlim (* args , ** kwargs ):
10661065 """
10671066 Get or set the *x* limits of the current axes.
@@ -1226,15 +1225,14 @@ def rgrids(*args, **kwargs):
12261225 """
12271226 ax = gca ()
12281227 if not isinstance (ax , PolarAxes ):
1229- raise RuntimeError (' rgrids only defined for polar axes' )
1230- if len (args )== 0 :
1228+ raise RuntimeError (" rgrids only defined for polar axes" )
1229+ if len (args ) == 0 :
12311230 lines = ax .yaxis .get_gridlines ()
12321231 labels = ax .yaxis .get_ticklabels ()
12331232 else :
12341233 lines , labels = ax .set_rgrids (* args , ** kwargs )
1235-
1236- return ( silent_list ('Line2D rgridline' , lines ),
1237- silent_list ('Text rgridlabel' , labels ) )
1234+ return (silent_list ("Line2D rgridline" , lines ),
1235+ silent_list ("Text rgridlabel" , labels ))
12381236
12391237
12401238def thetagrids (* args , ** kwargs ):
@@ -1272,31 +1270,27 @@ def thetagrids(*args, **kwargs):
12721270
12731271 - *labels* are :class:`~matplotlib.text.Text` instances.
12741272
1275- Note that on input, the *labels* argument is a list of strings,
1276- and on output it is a list of :class:`~matplotlib.text.Text`
1277- instances.
1273+ Note that on input, the *labels* argument is a list of strings, and on
1274+ output it is a list of :class:`~matplotlib.text.Text` instances.
12781275
12791276 Examples::
12801277
12811278 # set the locations of the radial gridlines and labels
1282- lines, labels = thetagrids( range(45,360,90) )
1279+ lines, labels = thetagrids(range(45, 360, 90))
12831280
12841281 # set the locations and labels of the radial gridlines and labels
1285- lines, labels = thetagrids( range(45,360,90), ('NE', 'NW', 'SW','SE') )
1282+ lines, labels = thetagrids(range(45, 360, 90), ('NE', 'NW', 'SW', 'SE'))
12861283 """
12871284 ax = gca ()
12881285 if not isinstance (ax , PolarAxes ):
1289- raise RuntimeError (' rgrids only defined for polar axes' )
1290- if len (args )== 0 :
1286+ raise RuntimeError (" rgrids only defined for polar axes" )
1287+ if len (args ) == 0 :
12911288 lines = ax .xaxis .get_ticklines ()
12921289 labels = ax .xaxis .get_ticklabels ()
12931290 else :
12941291 lines , labels = ax .set_thetagrids (* args , ** kwargs )
1295-
1296- return (silent_list ('Line2D thetagridline' , lines ),
1297- silent_list ('Text thetagridlabel' , labels )
1298- )
1299-
1292+ return (silent_list ("Line2D thetagridline" , lines ),
1293+ silent_list ("Text thetagridlabel" , labels ))
13001294
13011295## Plotting Info ##
13021296
@@ -1363,16 +1357,15 @@ def colors():
13631357 Here is an example that creates a pale turquoise title::
13641358
13651359 title('Is this the best color?', color='#afeeee')
1366-
13671360 """
1368- pass
13691361
13701362
13711363def colormaps ():
13721364 """
13731365 Matplotlib provides a number of colormaps, and others can be added using
1374- :func:`~matplotlib.cm.register_cmap`. This function documents the built-in
1375- colormaps, and will also return a list of all registered colormaps if called.
1366+ `~matplotlib.cm.register_cmap`. This function documents the built-in
1367+ colormaps, and will also return a list of all registered colormaps if
1368+ called.
13761369
13771370 You can set the colormap for an image, pcolor, scatter, etc,
13781371 using a keyword argument::
@@ -1629,7 +1622,7 @@ def pad(s, l):
16291622 exclude = {"colormaps" , "colors" , "connect" , "disconnect" ,
16301623 "get_current_fig_manager" , "ginput" , "plotting" ,
16311624 "waitforbuttonpress" }
1632- commands = sorted (set (__all__ ) - exclude - set (colormaps ()))
1625+ commands = sorted (set (__all__ ) - exclude - set (colormaps ()))
16331626
16341627 first_sentence = re .compile (r"(?:\s*).+?\.(?:\s+|$)" , flags = re .DOTALL )
16351628
@@ -1677,9 +1670,7 @@ def colorbar(mappable=None, cax=None, ax=None, **kw):
16771670 'with contourf).' )
16781671 if ax is None :
16791672 ax = gca ()
1680-
1681- ret = gcf ().colorbar (mappable , cax = cax , ax = ax , ** kw )
1682- return ret
1673+ return gcf ().colorbar (mappable , cax = cax , ax = ax , ** kw )
16831674colorbar .__doc__ = matplotlib .colorbar .colorbar_doc
16841675
16851676
@@ -1744,7 +1735,6 @@ def matshow(A, fignum=None, **kw):
17441735 kwarg to "lower" if you want the first row in the array to be
17451736 at the bottom instead of the top.
17461737
1747-
17481738 *fignum*: [ None | integer | False ]
17491739 By default, :func:`matshow` creates a new figure window with
17501740 automatic numbering. If *fignum* is given as an integer, the
@@ -1759,9 +1749,9 @@ def matshow(A, fignum=None, **kw):
17591749 if fignum is False or fignum is 0 :
17601750 ax = gca ()
17611751 else :
1762- # Extract actual aspect ratio of array and make appropriately sized figure
1752+ # Extract array's actual aspect ratio; make appropriately sized figure.
17631753 fig = figure (fignum , figsize = figaspect (A ))
1764- ax = fig .add_axes ([0.15 , 0.09 , 0.775 , 0.775 ])
1754+ ax = fig .add_axes ([0.15 , 0.09 , 0.775 , 0.775 ])
17651755
17661756 im = ax .matshow (A , ** kw )
17671757 sci (im )
0 commit comments