8000 Some docstring fixes and change a raise type by anntzer · Pull Request #10093 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Some docstring fixes and change a raise type #10093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api/api_changes/2017-12-26-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
`~.tight_layout.auto_adjust_subplotpars` now raises `ValueError` instead of `RuntimeError` when sizes of input lists don't match
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this long line of ``````s do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a very long title... (I don't think this entry deserves both a title and some contents in the section.)

2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_skew.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_set_line_coll_dash_image():


@image_comparison(baseline_images=['skew_rects'], remove_text=True)
def test_skew_rectange():
def test_skew_rectangle():

fix, axes = plt.subplots(5, 5, sharex=True, sharey=True, figsize=(16, 12))
axes = axes.flat
Expand Down
133 changes: 55 additions & 78 deletions lib/matplotlib/tight_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,77 +34,62 @@ def _get_top(tight_bbox, axes_bbox):
return tight_bbox.ymax - axes_bbox.ymax


def auto_adjust_subplotpars(fig, renderer,
nrows_ncols,
num1num2_list,
subplot_list,
ax_bbox_list=None,
pad=1.08, h_pad=None, w_pad=None,
rect=None):
def auto_adjust_subplotpars(
fig, renderer, nrows_ncols, num1num2_list, subplot_list,
ax_bbox_list=None, pad=1.08, h_pad=None, w_pad=None, rect=None):
"""
Return a dictionary of subplot parameters so that spacing between
subplots are adjusted. Note that this function ignore geometry
information of subplot itself, but uses what is given by
*nrows_ncols* and *num1num2_list* parameteres. Also, the results could be
incorrect if some subplots have ``adjustable=datalim``.

Parameters:

nrows_ncols
number of rows and number of columns of the grid.

num1num2_list
list of numbers specifying the area occupied by the subplot

subplot_list
list of subplots that will be used to calcuate optimal subplot_params.

Return a dict of subplot parameters to adjust spacing between subplots.

Note that this function ignores geometry information of subplot
itself, but uses what is given by the *nrows_ncols* and *num1num2_list*
parameters. Also, the results could be incorrect if some subplots have
``adjustable=datalim``.

Parameters
----------
nrows_ncols : Tuple[int, int]
Number of rows and number of columns of the grid.
num1num2_list : List[int]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a standard way of documenting lists of ints (for example)? It looks new to me, and if it is the standard it should be in our documentation guide to avoid confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested in #9271 ("typehints-style"), and OK'd by @tacaswell further down the comments.
Will edit the style guide in a separate PR.

List of numbers specifying the area occupied by the subplot
subplot_list : list of subplots
List of subplots that will be used to calculate optimal subplot_params.
pad : float
padding b 10000 etween the figure edge and the edges of subplots, as a fraction
of the font-size.
Padding between the figure edge and the edges of subplots, as a
fraction of the font size.
h_pad, w_pad : float
padding (height/width) between edges of adjacent subplots.
Defaults to `pad_inches`.

rect
[left, bottom, right, top] in normalized (0, 1) figure coordinates.
Padding (height/width) between edges of adjacent subplots, as a
fraction of the font size. Defaults to *pad*.
rect : Tuple[float, float, float, float]
[left, bottom, right, top] in normalized (0, 1) figure coordinates.
"""
rows, cols = nrows_ncols

pad_inches = pad * FontProperties(
size=rcParams["font.size"]).get_size_in_points() / 72.

font_size_inches = (
FontProperties(size=rcParams["font.size"]).get_size_in_points() / 72)
pad_inches = pad * font_size_inches
if h_pad is not None:
vpad_inches = h_pad * FontProperties(
size=rcParams["font.size"]).get_size_in_points() / 72.
vpad_inches = h_pad * font_size_inches
else:
vpad_inches = pad_inches

if w_pad is not None:
hpad_inches = w_pad * FontProperties(
size=rcParams["font.size"]).get_size_in_points() / 72.
hpad_inches = w_pad * font_size_inches
else:
hpad_inches = pad_inches

if len(subplot_list) == 0:
raise RuntimeError("")

if len(num1num2_list) != len(subplot_list):
raise RuntimeError("")
if len(num1num2_list) != len(subplot_list) or len(subplot_list) == 0:
raise ValueError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think changing the type of error is an API change, so this could do with an API note if it's going in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


if rect is None:
margin_left = None
margin_bottom = None
margin_right = None
margin_top = None
margin_left = margin_bottom = margin_right = margin_top = None
else:
margin_left, margin_bottom, _right, _top = rect
if _right:
margin_right = 1. - _right
margin_right = 1 - _right
else:
margin_right = None
if _top:
margin_top = 1. - _top
margin_top = 1 - _top
else:
margin_top = None

Expand Down Expand Up @@ -262,42 +247,34 @@ def get_subplotspec_list(axes_list, grid_spec=None):
def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
pad=1.08, h_pad=None, w_pad=None, r 6DB6 ect=None):
"""
Return subplot parameters for tight-layouted-figure with specified
padding.

Parameters:

*fig* : figure instance

*axes_list* : a list of axes

*subplotspec_list* : a list of subplotspec associated with each
axes in axes_list

*renderer* : renderer instance

*pad* : float
padding between the figure edge and the edges of subplots,
as a fraction of the font-size.

*h_pad*, *w_pad* : float
padding (height/width) between edges of adjacent subplots.
Defaults to `pad_inches`.

*rect* : if rect is given, it is interpreted as a rectangle
(left, bottom, right, top) in the normalized figure
coordinate that the whole subplots area (including
labels) will fit into. Default is (0, 0, 1, 1).
Return subplot parameters for tight-layouted-figure with specified padding.

Parameters
----------
fig : Figure
axes_list : list of Axes
subplotspec_list : list of `~.SubplotSpec`
The subplotspecs of each axes.
renderer : renderer
pad : float
Padding between the figure edge and the edges of subplots, as a
fraction of the font size.
h_pad, w_pad : float
Padding (height/width) between edges of adjacent subplots. Defaults to
*pad_inches*.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this in inches, and the other pad in fraction of font size? Not your fault, but I find these random units pretty annoying. At least here we should be explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarified

rect : Tuple[float, float, float, float], optional
(left, bottom, right, top) rectangle in normalized figure coordinates
that the whole subplots area (including labels) will fit into.
Defaults to using the entire figure.
"""

subplot_list = []
nrows_list = []
ncols_list = []
ax_bbox_list = []

subplot_dict = {} # multiple axes can share
# same subplot_interface (e.g., axes_grid1). Thus
# we need to join them together.
subplot_dict = {} # Multiple axes can share same subplot_interface (e.g.,
# axes_grid1); thus we need to join them together.

subplotspec_list2 = []

Expand Down
33 changes: 15 additions & 18 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2450,16 +2450,14 @@ class LassoSelector(_SelectorWidget):
"""
Selection curve of an arbitrary shape.

For the selector to remain responsive you must keep a reference to
it.
For the selector to remain responsive you must keep a reference to it.

The selected path can be used in conjunction with
:func:`~matplotlib.path.Path.contains_point` to select
data points from an image.
The selected path can be used in conjunction with `~.Path.contains_point`
to select data points from an image.

In contrast to :class:`Lasso`, `LassoSelector` is written with an interface
similar to :class:`RectangleSelector` and :class:`SpanSelector` and will
continue to interact with the axes until disconnected.
In contrast to `Lasso`, `LassoSelector` is written with an interface
similar to `RectangleSelector` and `SpanSelector`, and will continue to
interact with the axes until disconnected.

Example usage::

Expand All @@ -2477,17 +2475,17 @@ def onselect(verts):
onselect : function
Whenever the lasso is released, the *onselect* function is called and
passed the vertices of the selected path.
button : list[Int], optional
button : List[Int], optional
A list of integers indicating which mouse buttons should be used for
rectangle selection. You can also specify a single integer if only a
single button is desired. Default is ``None``, which does not limit
which button can be used.

Note, typically:

- 1 = left mouse button
- 2 = center mouse button (scroll wheel)
- 3 = right mouse button
- 1 = left mouse button
- 2 = center mouse button (scroll wheel)
- 3 = right mouse button

"""

Expand Down Expand Up @@ -2758,16 +2756,15 @@ class Lasso(AxesWidget):
Unlike :class:`LassoSelector`, this must be initialized with a starting
point `xy`, and the `Lasso` events are destroyed upon release.

Parameters:

*ax* : :class:`~matplotlib.axes.Axes`
Parameters
----------
ax : `~matplotlib.axes.Axes`
The parent axes for the widget.
*xy* : array
xy : array
Coordinates of the start of the lasso.
*callback* : function
callback : callable
Whenever the lasso is released, the `callback` function is called and
passed the vertices of the selected path.

"""

def __init__(self, ax, xy, callback=None, useblit=True):
Expand Down
0