8000 Some docstring fixes. · matplotlib/matplotlib@84379a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84379a5

Browse files
committed
Some docstring fixes.
1 parent f96fac0 commit 84379a5

File tree

3 files changed

+81
-105
lines changed

3 files changed

+81
-105
lines changed

doc/api/api_changes/2017-12-26-AL.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
`~.tight_layout.auto_adjust_subplotpars` now raises `ValueError` instead of `RuntimeError` when sizes of input lists don't match
2+
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````

lib/matplotlib/tight_layout.py

Lines changed: 55 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -34,77 +34,62 @@ def _get_top(tight_bbox, axes_bbox):
3434
return tight_bbox.ymax - axes_bbox.ymax
3535

3636

37-
def auto_adjust_subplotpars(fig, renderer,
38-
nrows_ncols,
39-
num1num2_list,
40-
subplot_list,
41-
ax_bbox_list=None,
42-
pad=1.08, h_pad=None, w_pad=None,
43-
rect=None):
37+
def auto_adjust_subplotpars(
38+
fig, renderer, nrows_ncols, num1num2_list, subplot_list,
39+
ax_bbox_list=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
4440
"""
45-
Return a dictionary of subplot parameters so that spacing between
46-
subplots are adjusted. Note that this function ignore geometry
47-
information of subplot itself, but uses what is given by
48-
*nrows_ncols* and *num1num2_list* parameteres. Also, the results could be
49-
incorrect if some subplots have ``adjustable=datalim``.
50-
51-
Parameters:
52-
53-
nrows_ncols
54-
number of rows and number of columns of the grid.
55-
56-
num1num2_list
57-
list of numbers specifying the area occupied by the subplot
58-
59-
subplot_list
60-
list of subplots that will be used to calcuate optimal subplot_params.
61-
41+
Return a dict of subplot parameters to adjust spacing between subplots.
42+
43+
Note that this function ignores geometry information of subplot
44+
itself, but uses what is given by the *nrows_ncols* and *num1num2_list*
45+
parameters. Also, the results could be incorrect if some subplots have
46+
``adjustable=datalim``.
47+
48+
Parameters
49+
----------
50+
nrows_ncols : Tuple[int, int]
51+
Number of rows and number of columns of the grid.
52+
num1num2_list : List[int]
53+
List of numbers specifying the area occupied by the subplot
54+
subplot_list : list of subplots
55+
List of subplots that will be used to calculate optimal subplot_params.
6256
pad : float
63-
padding between the figure edge and the edges of subplots, as a fraction
64-
of the font-size.
57+
Padding between the figure edge and the edges of subplots, as a
58+
fraction of the font size.
6559
h_pad, w_pad : float
66-
padding (height/width) between edges of adjacent subplots.
67-
Defaults to `pad_inches`.
68-
69-
rect
70-
[left, bottom, right, top] in normalized (0, 1) figure coordinates.
60+
Padding (height/width) between edges of adjacent subplots. Defaults to
61+
*pad_inches*.
62+
rect : Tuple[float, float, float, float]
63+
[left, bottom, right, top] in normalized (0, 1) figure coordinates.
7164
"""
7265
rows, cols = nrows_ncols
7366

74-
pad_inches = pad * FontProperties(
75-
size=rcParams["font.size"]).get_size_in_points() / 72.
76-
67+
font_size_inches = (
68+
FontProperties(size=rcParams["font.size"]).get_size_in_points() / 72)
69+
pad_inches = pad * font_size_inches
7770
if h_pad is not None:
78-
vpad_inches = h_pad * FontProperties(
79-
size=rcParams["font.size"]).get_size_in_points() / 72.
71+
vpad_inches = h_pad * font_size_inches
8072
else:
8173
vpad_inches = pad_inches
8274

8375
if w_pad is not None:
84-
hpad_inches = w_pad * FontProperties(
85-
size=rcParams["font.size"]).get_size_in_points() / 72.
76+
hpad_inches = w_pad * font_size_inches
8677
else:
8778
hpad_inches = pad_inches
8879

89-
if len(subplot_list) == 0:
90-
raise RuntimeError("")
91-
92-
if len(num1num2_list) != len(subplot_list):
93-
raise RuntimeError("")
80+
if len(num1num2_list) != len(subplot_list) or len(subplot_list) == 0:
81+
raise ValueError
9482

9583
if rect is None:
96-
margin_left = None
97-
margin_bottom = None
98-
margin_right = None
99-
margin_top = None
84+
margin_left = margin_bottom = margin_right = margin_top = None
10085
else:
10186
margin_left, margin_bottom, _right, _top = rect
10287
if _right:
103-
margin_right = 1. - _right
88+
margin_right = 1 - _right
10489
else:
10590
margin_right = None
10691
if _top:
107-
margin_top = 1. - _top
92+
margin_top = 1 - _top
10893
else:
10994
margin_top = None
11095

@@ -262,42 +247,34 @@ def get_subplotspec_list(axes_list, grid_spec=None):
262247
def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
263248
pad=1.08, h_pad=None, w_pad=None, rect=None):
264249
"""
265-
Return subplot parameters for tight-layouted-figure with specified
266-
padding.
267-
268-
Parameters:
269-
270-
*fig* : figure instance
271-
272-
*axes_list* : a list of axes
273-
274-
*subplotspec_list* : a list of subplotspec associated with each
275-
axes in axes_list
276-
277-
*renderer* : renderer instance
278-
279-
*pad* : float
280-
padding between the figure edge and the edges of subplots,
281-
as a fraction of the font-size.
282-
283-
*h_pad*, *w_pad* : float
284-
padding (height/width) between edges of adjacent subplots.
285-
Defaults to `pad_inches`.
286-
287-
*rect* : if rect is given, it is interpreted as a rectangle
288-
(left, bottom, right, top) in the normalized figure
289-
coordinate that the whole subplots area (including
290-
labels) will fit into. Default is (0, 0, 1, 1).
250+
Return subplot parameters for tight-layouted-figure with specified padding.
251+
252+
Parameters
253+
----------
254+
fig : Figure
255+
axes_list : List[Axes]
256+
subplotspec_list : List[SubplotSpec]
257+
The subplotspecs of each axes.
258+
renderer : renderer
259+
pad : float
260+
Padding between the figure edge and the edges of subplots, as a
261+
fraction of the font size.
262+
h_pad, w_pad : float
263+
Padding (height/width) between edges of adjacent subplots. Defaults to
264+
*pad_inches*.
265+
rect : Tuple[float, float, float, float], optional
266+
(left, bottom, right, top) rectangle in normalized figure coordinates
267+
that the whole subplots area (including labels) will fit into.
268+
Defaults to using the entire figure.
291269
"""
292270

293271
subplot_list = []
294272
nrows_list = []
295273
ncols_list = []
296274
ax_bbox_list = []
297275

298-
subplot_dict = {} # multiple axes can share
299-
# same subplot_interface (e.g., axes_grid1). Thus
300-
# we need to join them together.
276+
subplot_dict = {} # Multiple axes can share same subplot_interface (e.g.,
277+
# axes_grid1); thus we need to join them together.
301278

302279
subplotspec_list2 = []
303280

lib/matplotlib/widgets.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,8 +2453,7 @@ def _rect_bbox(self):
24532453
class LassoSelector(_SelectorWidget):
24542454
"""Selection curve of an arbitrary shape.
24552455
2456-
For the selector to remain responsive you must keep a reference to
2457-
it.
2456+
For the selector to remain responsive you must keep a reference to it.
24582457
24592458
The selected path can be used in conjunction with
24602459
:func:`~matplotlib.path.Path.contains_point` to select
@@ -2464,14 +2463,6 @@ class LassoSelector(_SelectorWidget):
24642463
similar to :class:`RectangleSelector` and :class:`SpanSelector` and will
24652464
continue to interact with the axes until disconnected.
24662465
2467-
Parameters:
2468-
2469-
*ax* : :class:`~matplotlib.axes.Axes`
2470-
The parent axes for the widget.
2471-
*onselect* : function
2472-
Whenever the lasso is released, the `onselect` function is called and
2473-
passed the vertices of the selected path.
2474-
24752466
Example usage::
24762467
24772468
ax = subplot(111)
@@ -2480,21 +2471,28 @@ class LassoSelector(_SelectorWidget):
24802471
def onselect(verts):
24812472
print(verts)
24822473
lasso = LassoSelector(ax, onselect)
2483-
2484-
*button* is a list of integers indicating which mouse buttons should
2485-
be used for rectangle selection. You can also specify a single
2486-
integer if only a single button is desired. Default is *None*,
2487-
which does not limit which button can be used.
2488-
2489-
Note, typically:
2490-
1 = left mouse button
2491-
2 = center mouse button (scroll wheel)
2492-
3 = right mouse button
2493-
24942474
"""
24952475

24962476
def __init__(self, ax, onselect=None, useblit=True, lineprops=None,
24972477
button=None):
2478+
"""
2479+
Parameters
2480+
----------
2481+
ax : `~matplotlib.axes.Axes`
2482+
The parent axes for the widget.
2483+
onselect : callable
2484+
Whenever the lasso is released, the *onselect* function is called
2485+
and passed the vertices of the selected path.
2486+
button : int or List[int]
2487+
Integer or list of integers indicating which mouse buttons should
2488+
be used for rectangle selection. Default is ``None``, which does
2489+
not limit which button can be used.
2490+
2491+
Note, typically:
2492+
1 = left mouse button
2493+
2 = center mouse button (scroll wheel)
2494+
3 = right mouse button
2495+
"""
24982496
_SelectorWidget.__init__(self, ax, onselect, useblit=useblit,
24992497
button=button)
25002498

@@ -2760,16 +2758,15 @@ class Lasso(AxesWidget):
27602758
Unlike :class:`LassoSelector`, this must be initialized with a starting
27612759
point `xy`, and the `Lasso` events are destroyed upon release.
27622760
2763-
Parameters:
2764-
2765-
*ax* : :class:`~matplotlib.axes.Axes`
2761+
Parameters
2762+
----------
2763+
ax : `~matplotlib.axes.Axes`
27662764
The parent axes for the widget.
2767-
*xy* : array
2765+
xy : array
27682766
Coordinates of the start of the lasso.
2769-
*callback* : function
2767+
callback : callable
27702768
Whenever the lasso is released, the `callback` function is called and
27712769
passed the vertices of the selected path.
2772-
27732770
"""
27742771

27752772
def __init__(self, ax, xy, callback=None, useblit=True):

0 commit comments

Comments
 (0)
0