20
20
21
21
import inspect
22
22
from numbers import Number
23
+ import re
23
24
import sys
24
25
import time
25
26
import warnings
@@ -121,8 +122,7 @@ def install_repl_displayhook():
121
122
Install a repl display hook so that any stale figure are automatically
122
123
redrawn when control is returned to the repl.
123
124
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.
126
126
"""
127
127
global _IP_REGISTERED
128
128
global _INSTALL_FIG_OBSERVER
@@ -844,13 +844,13 @@ def axes(arg=None, **kwargs):
844
844
845
845
def delaxes (ax = None ):
846
846
"""
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.
850
850
"""
851
851
if ax is None :
852
852
ax = gca ()
853
- gcf () .delaxes (ax )
853
+ ax . figure .delaxes (ax )
854
854
855
855
856
856
def sca (ax ):
@@ -865,7 +865,7 @@ def sca(ax):
865
865
_pylab_helpers .Gcf .set_active (m )
866
866
m .canvas .figure .sca (ax )
867
867
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" )
869
869
870
870
871
871
def gca (** kwargs ):
@@ -992,7 +992,7 @@ def subplot(*args, **kwargs):
992
992
def subplots (nrows = 1 , ncols = 1 , sharex = False , sharey = False , squeeze = True ,
993
993
subplot_kw = None , gridspec_kw = None , ** fig_kw ):
994
994
"""
995
- Create a figure and a set of subplots
995
+ Create a figure and a set of subplots.
996
996
997
997
This utility wrapper makes it convenient to create common layouts of
998
998
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):
1269
1269
figure coordinate that the whole subplots area (including
1270
1270
labels) will fit into. Default is (0, 0, 1, 1).
1271
1271
"""
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 )
1274
1273
1275
1274
1276
1275
def box (on = None ):
@@ -1885,53 +1884,44 @@ def colormaps():
1885
1884
1886
1885
def _setup_pyplot_info_docstrings ():
1887
1886
"""
1888
- Generates the plotting and docstring.
1887
+ Generates the plotting docstring.
1889
1888
1890
1889
These must be done after the entire module is imported, so it is
1891
1890
called from the end of this module, which is generated by
1892
1891
boilerplate.py.
1893
1892
"""
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
-
1903
1893
commands = get_plot_commands ()
1904
1894
1905
1895
first_sentence = re .compile (r"(?:\s*).+?\.(?:\s+|$)" , flags = re .DOTALL )
1906
1896
1907
1897
# Collect the first sentence of the docstring for all of the
1908
1898
# plotting commands.
1909
1899
rows = []
1910
- max_name = 0
1911
- max_summary = 0
1900
+ max_name = len ( "Function" )
1901
+ max_summary = len ( "Description" )
1912
1902
for name in commands :
1913
1903
doc = globals ()[name ].__doc__
1914
1904
summary = ''
1915
1905
if doc is not None :
1916
1906
match = first_sentence .match (doc )
1917
1907
if match is not None :
1918
- summary = match .group (0 ). strip ( ).replace ('\n ' , ' ' )
1908
+ summary = inspect . cleandoc ( match .group (0 )).replace ('\n ' , ' ' )
1919
1909
name = '`%s`' % name
1920
1910
rows .append ([name , summary ])
1921
1911
max_name = max (max_name , len (name ))
1922
1912
max_summary = max (max_summary , len (summary ))
1923
1913
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
+ ]
1935
1925
plotting .__doc__ = '\n ' .join (lines )
1936
1926
1937
1927
0 commit comments