-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
@@ -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*. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = [] | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)