2020
2121import inspect
2222from numbers import Number
23+ import re
2324import sys
2425import time
2526import warnings
@@ -121,8 +122,7 @@ def install_repl_displayhook():
121122 Install a repl display hook so that any stale figure are automatically
122123 redrawn when control is returned to the repl.
123124
124- This works with IPython terminals and kernels,
125- as well as vanilla python shells.
125+ This works both with IPython and with vanilla python shells.
126126 """
127127 global _IP_REGISTERED
128128 global _INSTALL_FIG_OBSERVER
@@ -844,13 +844,13 @@ def axes(arg=None, **kwargs):
844844
845845def delaxes (ax = None ):
846846 """
847- Remove the given `Axes` *ax* from the current figure. If *ax* is *None*,
848- the current axes is removed. A KeyError is raised if the axes doesn't
849- exist.
847+ Remove the `Axes` *ax* (defaulting to the current axes) from its figure.
848+
849+ A KeyError is raised if the axes doesn't exist.
850850 """
851851 if ax is None :
852852 ax = gca ()
853- gcf () .delaxes (ax )
853+ ax . figure .delaxes (ax )
854854
855855
856856def sca (ax ):
@@ -865,7 +865,7 @@ def sca(ax):
865865 _pylab_helpers .Gcf .set_active (m )
866866 m .canvas .figure .sca (ax )
867867 return
868- raise ValueError ("Axes instance argument was not found in a figure. " )
868+ raise ValueError ("Axes instance argument was not found in a figure" )
869869
870870
871871def gca (** kwargs ):
@@ -992,7 +992,7 @@ def subplot(*args, **kwargs):
992992def subplots (nrows = 1 , ncols = 1 , sharex = False , sharey = False , squeeze = True ,
993993 subplot_kw = None , gridspec_kw = None , ** fig_kw ):
994994 """
995- Create a figure and a set of subplots
995+ Create a figure and a set of subplots.
996996
997997 This utility wrapper makes it convenient to create common layouts of
998998 subplots, including the enclosing figure object, in a single call.
@@ -1269,8 +1269,7 @@ def tight_layout(pad=1.08, h_pad=None, w_pad=None, rect=None):
12691269 figure coordinate that the whole subplots area (including
12701270 labels) will fit into. Default is (0, 0, 1, 1).
12711271 """
1272- fig = gcf ()
1273- fig .tight_layout (pad = pad , h_pad = h_pad , w_pad = w_pad , rect = rect )
1272+ gcf ().tight_layout (pad = pad , h_pad = h_pad , w_pad = w_pad , rect = rect )
12741273
12751274
12761275def box (on = None ):
@@ -1885,53 +1884,44 @@ def colormaps():
18851884
18861885def _setup_pyplot_info_docstrings ():
18871886 """
1888- Generates the plotting and docstring.
1887+ Generates the plotting docstring.
18891888
18901889 These must be done after the entire module is imported, so it is
18911890 called from the end of this module, which is generated by
18921891 boilerplate.py.
18931892 """
1894- # Generate the plotting docstring
1895- import re
1896-
1897- def pad (s , l ):
1898- """Pad string *s* to length *l*."""
1899- if l < len (s ):
1900- return s [:l ]
1901- return s + ' ' * (l - len (s ))
1902-
19031893 commands = get_plot_commands ()
19041894
19051895 first_sentence = re .compile (r"(?:\s*).+?\.(?:\s+|$)" , flags = re .DOTALL )
19061896
19071897 # Collect the first sentence of the docstring for all of the
19081898 # plotting commands.
19091899 rows = []
1910- max_name = 0
1911- max_summary = 0
1900+ max_name = len ( "Function" )
1901+ max_summary = len ( "Description" )
19121902 for name in commands :
19131903 doc = globals ()[name ].__doc__
19141904 summary = ''
19151905 if doc is not None :
19161906 match = first_sentence .match (doc )
19171907 if match is not None :
1918- summary = match .group (0 ). strip ( ).replace ('\n ' , ' ' )
1908+ summary = inspect . cleandoc ( match .group (0 )).replace ('\n ' , ' ' )
19191909 name = '`%s`' % name
19201910 rows .append ([name , summary ])
19211911 max_name = max (max_name , len (name ))
19221912 max_summary = max (max_summary , len (summary ))
19231913
1924- lines = []
1925- sep = '=' * max_name + ' ' + '=' * max_summary
1926- lines . append ( sep )
1927- lines . append ( ' ' . join ([ pad ( " Function" , max_name ),
1928- pad ( "Description" , max_summary )]))
1929- lines . append ( sep )
1930- for name , summary in rows :
1931- lines . append ( ' ' . join ([ pad ( name , max_name ),
1932- pad ( summary , max_summary )]))
1933- lines . append ( sep )
1934-
1914+ separator = '=' * max_name + ' ' + '=' * max_summary
1915+ lines = [
1916+ separator ,
1917+ '{:{}} {:{}}' . format ( ' Function' , max_name , 'Description' , max_summary ),
1918+ separator ,
1919+ ] + [
1920+ '{:{}} {:{}}' . format ( name , max_name , summary , max_summary )
1921+ for name , summary in rows
1922+ ] + [
1923+ separator ,
1924+ ]
19351925 plotting .__doc__ = '\n ' .join (lines )
19361926
19371927
0 commit comments