6363 MaxNLocator
6464from matplotlib .backends import pylab_setup
6565
66+
6667## Backend detection ##
68+
6769def _backend_selection ():
6870 """ If rcParams['backend_fallback'] is true, check to see if the
6971 current backend is compatible with the current running event
@@ -73,7 +75,7 @@ def _backend_selection():
7375 if not rcParams ['backend_fallback' ] or backend not in _interactive_bk :
7476 return
7577 is_agg_backend = rcParams ['backend' ].endswith ('Agg' )
76- if 'wx' in sys .modules and not backend in ('WX' , 'WXAgg' ):
78+ if 'wx' in sys .modules and backend not in ('WX' , 'WXAgg' ):
7779 import wx
7880 if wx .App .IsMainLoopRunning ():
7981 rcParams ['backend' ] = 'wx' + 'Agg' * is_agg_backend
@@ -223,7 +225,8 @@ def switch_backend(newbackend):
223225 global _backend_mod , new_figure_manager , draw_if_interactive , _show
224226 matplotlib .use (newbackend , warn = False , force = True )
225227 from matplotlib .backends import pylab_setup
226- _backend_mod , new_figure_manager , draw_if_interactive , _show = pylab_setup ()
228+ _backend_mod , new_figure_manager , draw_if_interactive , _show = \
229+ pylab_setup ()
227230
228231
229232def show (* args , ** kw ):
@@ -281,10 +284,8 @@ def pause(interval):
281284 else :
282285 time .sleep (interval )
283286
284-
285287## Any Artist ##
286288
287-
288289def xkcd (scale = 1 , length = 100 , randomness = 2 ):
289290 """
290291 Turns on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode.
@@ -357,7 +358,6 @@ def __enter__(self):
357358
358359 return dummy_ctx ()
359360
360-
361361## Figures ##
362362
363363def figure (num = None , # autoincrement if None, else integer from 1-N
@@ -602,10 +602,8 @@ def close(*args):
602602 else :
603603 raise TypeError ('close takes 0 or 1 arguments' )
604604
605-
606605## Axes ##
607606
608-
609607def axes (* args , ** kwargs ):
610608 """
611609 Add an axes to the figure.
@@ -728,12 +726,13 @@ def subplot(*args, **kwargs):
728726 import matplotlib.pyplot as plt
729727 # plot a line, implicitly creating a subplot(111)
730728 plt.plot([1,2,3])
731- # now create a subplot which represents the top plot of a grid
732- # with 2 rows and 1 column. Since this subplot will overlap the
733- # first, the plot (and its axes) previously created, will be removed
729+ # now create a subplot which represents the top plot of a grid with
730+ # 2 rows and 1 column. Since this subplot will overlap the first, the
731+ # plot (and its axes) previously created, will be removed
734732 plt.subplot(211)
735733 plt.plot(range(12))
736- plt.subplot(212, facecolor='y') # creates 2nd subplot with yellow background
734+ # create a second subplot with yellow background
735+ plt.subplot(212, facecolor='y')
737736
738737 If you do not want this behavior, use the
739738 :meth:`~matplotlib.figure.Figure.add_subplot` method or the
@@ -770,28 +769,26 @@ def subplot(*args, **kwargs):
770769
771770 """
772771 # if subplot called without arguments, create subplot(1,1,1)
773- if len (args )== 0 :
774- args = (1 ,1 , 1 )
772+ if len (args ) == 0 :
773+ args = (1 , 1 , 1 )
775774
776775 # This check was added because it is very easy to type
777776 # subplot(1, 2, False) when subplots(1, 2, False) was intended
778777 # (sharex=False, that is). In most cases, no error will
779778 # ever occur, but mysterious behavior can result because what was
780779 # intended to be the sharex argument is instead treated as a
781780 # subplot index for subplot()
782- if len (args ) >= 3 and isinstance (args [2 ], bool ) :
783- warnings .warn ("The subplot index argument to subplot() appears"
784- " to be a boolean. Did you intend to use subplots()?" )
781+ if len (args ) >= 3 and isinstance (args [2 ], bool ):
782+ warnings .warn ("The subplot index argument to subplot() appears "
783+ "to be a boolean. Did you intend to use subplots()?" )
785784
786785 fig = gcf ()
787786 a = fig .add_subplot (* args , ** kwargs )
788787 bbox = a .bbox
789- byebye = []
790- for other in fig .axes :
791- if other == a : continue
792- if bbox .fully_overlaps (other .bbox ):
793- byebye .append (other )
794- for ax in byebye : delaxes (ax )
788+ byebye = [other for other in fig .axes
789+ if other is not a and bbox .fully_overlaps (other .bbox )]
790+ for ax in byebye :
791+ delaxes (ax )
795792
796793 return a
797794
@@ -1013,24 +1010,28 @@ def subplot_tool(targetfig=None):
10131010 """
10141011 Launch a subplot tool window for a figure.
10151012
1016- A :class:`matplotlib.widgets.SubplotTool` instance is returned.
1013+ Returns
1014+ -------
1015+ `matplotlib.widgets.SubplotTool`
10171016 """
1018- tbar = rcParams [' toolbar' ] # turn off the navigation toolbar for the toolfig
1019- rcParams [' toolbar' ] = ' None'
1017+ tbar = rcParams [" toolbar" ] # Turn off the nav toolbar for the toolfig.
1018+ rcParams [" toolbar" ] = " None"
10201019 if targetfig is None :
10211020 manager = get_current_fig_manager ()
10221021 targetfig = manager .canvas .figure
10231022 else :
1024- # find the manager for this figure
1023+ # Find the manager for this figure.
10251024 for manager in _pylab_helpers .Gcf ._activeQue :
1026- if manager .canvas .figure == targetfig : break
1027- else : raise RuntimeError ('Could not find manager for targetfig' )
1025+ if manager .canvas .figure == targetfig :
1026+ break
1027+ else :
1028+ raise RuntimeError ("Could not find manager for targetfig" )
10281029
1029- toolfig = figure (figsize = (6 ,3 ))
1030+ toolfig = figure (figsize = (6 , 3 ))
10301031 toolfig .subplots_adjust (top = 0.9 )
1031- ret = SubplotTool (targetfig , toolfig )
1032- rcParams [' toolbar' ] = tbar
1033- _pylab_helpers .Gcf .set_active (manager ) # restore the current figure
1032+ ret = SubplotTool (targetfig , toolfig )
1033+ rcParams [" toolbar" ] = tbar
1034+ _pylab_helpers .Gcf .set_active (manager ) # Restore the current figure.
10341035 return ret
10351036
10361037
@@ -1047,10 +1048,8 @@ def box(on=None):
10471048 on = not ax .get_frame_on ()
10481049 ax .set_frame_on (on )
10491050
1050-
10511051## Axis ##
10521052
1053-
10541053def xlim (* args , ** kwargs ):
10551054 """
10561055 Get or set the *x* limits of the current axes.
@@ -1215,15 +1214,14 @@ def rgrids(*args, **kwargs):
12151214 """
12161215 ax = gca ()
12171216 if not isinstance (ax , PolarAxes ):
1218- raise RuntimeError (' rgrids only defined for polar axes' )
1219- if len (args )== 0 :
1217+ raise RuntimeError (" rgrids only defined for polar axes" )
1218+ if len (args ) == 0 :
12201219 lines = ax .yaxis .get_gridlines ()
12211220 labels = ax .yaxis .get_ticklabels ()
12221221 else :
12231222 lines , labels = ax .set_rgrids (* args , ** kwargs )
1224-
1225- return ( silent_list ('Line2D rgridline' , lines ),
1226- silent_list ('Text rgridlabel' , labels ) )
1223+ return (silent_list ("Line2D rgridline" , lines ),
1224+ silent_list ("Text rgridlabel" , labels ))
12271225
12281226
12291227def thetagrids (* args , ** kwargs ):
@@ -1261,31 +1259,27 @@ def thetagrids(*args, **kwargs):
12611259
12621260 - *labels* are :class:`~matplotlib.text.Text` instances.
12631261
1264- Note that on input, the *labels* argument is a list of strings,
1265- and on output it is a list of :class:`~matplotlib.text.Text`
1266- instances.
1262+ Note that on input, the *labels* argument is a list of strings, and on
1263+ output it is a list of :class:`~matplotlib.text.Text` instances.
12671264
12681265 Examples::
12691266
12701267 # set the locations of the radial gridlines and labels
1271- lines, labels = thetagrids( range(45,360,90) )
1268+ lines, labels = thetagrids(range(45, 360, 90))
12721269
12731270 # set the locations and labels of the radial gridlines and labels
1274- lines, labels = thetagrids( range(45,360,90), ('NE', 'NW', 'SW','SE') )
1271+ lines, labels = thetagrids(range(45, 360, 90), ('NE', 'NW', 'SW', 'SE'))
12751272 """
12761273 ax = gca ()
12771274 if not isinstance (ax , PolarAxes ):
1278- raise RuntimeError (' rgrids only defined for polar axes' )
1279- if len (args )== 0 :
1275+ raise RuntimeError (" rgrids only defined for polar axes" )
1276+ if len (args ) == 0 :
12801277 lines = ax .xaxis .get_ticklines ()
12811278 labels = ax .xaxis .get_ticklabels ()
12821279 else :
12831280 lines , labels = ax .set_thetagrids (* args , ** kwargs )
1284-
1285- return (silent_list ('Line2D thetagridline' , lines ),
1286- silent_list ('Text thetagridlabel' , labels )
1287- )
1288-
1281+ return (silent_list ("Line2D thetagridline" , lines ),
1282+ silent_list ("Text thetagridlabel" , labels ))
12891283
12901284## Plotting Info ##
12911285
@@ -1352,16 +1346,15 @@ def colors():
13521346 Here is an example that creates a pale turquoise title::
13531347
13541348 title('Is this the best color?', color='#afeeee')
1355-
13561349 """
1357- pass
13581350
13591351
13601352def colormaps ():
13611353 """
13621354 Matplotlib provides a number of colormaps, and others can be added using
1363- :func:`~matplotlib.cm.register_cmap`. This function documents the built-in
1364- colormaps, and will also return a list of all registered colormaps if called.
1355+ `~matplotlib.cm.register_cmap`. This function documents the built-in
1356+ colormaps, and will also return a list of all registered colormaps if
1357+ called.
13651358
13661359 You can set the colormap for an image, pcolor, scatter, etc,
13671360 using a keyword argument::
@@ -1618,7 +1611,7 @@ def pad(s, l):
16181611 exclude = {"colormaps" , "colors" , "connect" , "disconnect" ,
16191612 "get_current_fig_manager" , "ginput" , "plotting" ,
16201613 "waitforbuttonpress" }
1621- commands = sorted (set (__all__ ) - exclude - set (colormaps ()))
1614+ commands = sorted (set (__all__ ) - exclude - set (colormaps ()))
16221615
16231616 first_sentence = re .compile (r"(?:\s*).+?\.(?:\s+|$)" , flags = re .DOTALL )
16241617
@@ -1666,9 +1659,7 @@ def colorbar(mappable=None, cax=None, ax=None, **kw):
16661659 'with contourf).' )
16671660 if ax is None :
16681661 ax = gca ()
1669-
1670- ret = gcf ().colorbar (mappable , cax = cax , ax = ax , ** kw )
1671- return ret
1662+ return gcf ().colorbar (mappable , cax = cax , ax = ax , ** kw )
16721663colorbar .__doc__ = matplotlib .colorbar .colorbar_doc
16731664
16741665
@@ -1733,7 +1724,6 @@ def matshow(A, fignum=None, **kw):
17331724 kwarg to "lower" if you want the first row in the array to be
17341725 at the bottom instead of the top.
17351726
1736-
17371727 *fignum*: [ None | integer | False ]
17381728 By default, :func:`matshow` creates a new figure window with
17391729 automatic numbering. If *fignum* is given as an integer, the
@@ -1748,9 +1738,9 @@ def matshow(A, fignum=None, **kw):
17481738 if fignum is False or fignum is 0 :
17491739 ax = gca ()
17501740 else :
1751- # Extract actual aspect ratio of array and make appropriately sized figure
1741+ # Extract array's actual aspect ratio; make appropriately sized figure.
17521742 fig = figure (fignum , figsize = figaspect (A ))
1753- ax = fig .add_axes ([0.15 , 0.09 , 0.775 , 0.775 ])
1743+ ax = fig .add_axes ([0.15 , 0.09 , 0.775 , 0.775 ])
17541744
17551745 im = ax .matshow (A , ** kw )
17561746 sci (im )
0 commit comments