Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 37978a8

Browse files
authored
Merge pull request #10093 from anntzer/more-docstring-fixes
Some docstring fixes and change a raise type
2 parents 4b60865 + 2c16696 commit 37978a8

File tree

4 files changed

+73
-97
lines changed

4 files changed

+73
-97
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/tests/test_skew.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def test_set_line_coll_dash_image():
188188

189189

190190
@image_comparison(baseline_images=['skew_rects'], remove_text=True)
191-
def test_skew_rectange():
191+
def test_skew_rectangle():
192192

193193
fix, axes = plt.subplots(5, 5, sharex=True, sharey=True, figsize=(16, 12))
194194
axes = axes.flat

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, as a
61+
fraction of the font size. Defaults to *pad*.
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 of Axes
256+
subplotspec_list : list of `~.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: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,16 +2450,14 @@ class LassoSelector(_SelectorWidget):
24502450
"""
24512451
Selection curve of an arbitrary shape.
24522452
2453-
For the selector to remain responsive you must keep a reference to
2454-
it.
2453+
For the selector to remain responsive you must keep a reference to it.
24552454
2456-
The selected path can be used in conjunction with
2457-
:func:`~matplotlib.path.Path.contains_point` to select
2458-
data points from an image.
2455+
The selected path can be used in conjunction with `~.Path.contains_point`
2456+
to select data points from an image.
24592457
2460-
In contrast to :class:`Lasso`, `LassoSelector` is written with an interface
2461-
similar to :class:`RectangleSelector` and :class:`SpanSelector` and will
2462-
continue to interact with the axes until disconnected.
2458+
In contrast to `Lasso`, `LassoSelector` is written with an interface
2459+
similar to `RectangleSelector` and `SpanSelector`, and will continue to
2460+
interact with the axes until disconnected.
24632461
24642462
Example usage::
24652463
@@ -2477,17 +2475,17 @@ def onselect(verts):
24772475
onselect : function
24782476
Whenever the lasso is released, the *onselect* function is called and
24792477
passed the vertices of the selected path.
2480-
button : list[Int], optional
2478+
button : List[Int], optional
24812479
A list of integers indicating which mouse buttons should be used for
24822480
rectangle selection. You can also specify a single integer if only a
24832481
single button is desired. Default is ``None``, which does not limit
24842482
which button can be used.
24852483
24862484
Note, typically:
24872485
2488-
- 1 = left mouse button
2489-
- 2 = center mouse button (scroll wheel)
2490-
- 3 = right mouse button
2486+
- 1 = left mouse button
2487+
- 2 = center mouse button (scroll wheel)
2488+
- 3 = right mouse button
24912489
24922490
"""
24932491

@@ -2758,16 +2756,15 @@ class Lasso(AxesWidget):
27582756
Unlike :class:`LassoSelector`, this must be initialized with a starting
27592757
point `xy`, and the `Lasso` events are destroyed upon release.
27602758
2761-
Parameters:
2762-
2763-
*ax* : :class:`~matplotlib.axes.Axes`
2759+
Parameters
2760+
----------
2761+
ax : `~matplotlib.axes.Axes`
27642762
The parent axes for the widget.
2765-
*xy* : array
2763+
xy : array
27662764
Coordinates of the start of the lasso.
2767-
*callback* : function
2765+
callback : callable
27682766
Whenever the lasso is released, the `callback` function is called and
27692767
passed the vertices of the selected path.
2770-
27712768
"""
27722769

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

0 commit comments

Comments
 (0)