-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
DOC: Constrained layout tutorial improvements #11388
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
DOC: Constrained layout tutorial improvements #11388
Conversation
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.
Looks good overall. Just some minor ReST/Sphinx issues.
@@ -83,7 +99,7 @@ def example_plot(ax, fontsize=12, nodec=False): | |||
example_plot(ax) | |||
|
|||
############################################################################### | |||
# Specifying `constrained_layout=True` in the call to `plt.subplots` | |||
# Specifying ``constrained_layout=True`` in the call to ``plt.subplots`` |
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.
Using plt.subplots(..., constrained_layout=True)
causes ...
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.
The sentence wasn't written by me, but I actually like it as it is. Otherwise it's too much doubled
Using
__code__
cause x to happen:__code__
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.
Ok, then leave it. The sentence feels quite verbose to me, but I won't start a discussion here.
@@ -102,9 +118,9 @@ def example_plot(ax, fontsize=12, nodec=False): | |||
# | |||
# .. note:: | |||
# | |||
# For the `pcolormesh` kwargs (``pc_kwargs``) we use a dictionary. | |||
# For the `~axes.Axes.pcolormesh` kwargs (``pc_kwargs``) we use a dictionary. |
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.
~.Axes.pcolormesh
(otherwise it would have to be ~axes._axes.Axes.pcolormesh
)
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.
This is the error I make most often with this kind of format. I always forget the leading dot.
~.axes.Axes.pcolormesh
works fine. I've been using this quite often in recent PRs. This is because axes/__init__.py
has from ._axes import *
in it. Hence matplotlib.axes.Axes.pcolormesh
is valid.
# Below we will assign one colorbar to a number of axes each containing | ||
# a `ScalarMappable`; specifying the norm and colormap ensures | ||
# a `~cm.ScalarMappable`; specifying the norm and colormap ensures |
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.
Not linking. Not sure why. is ;
after `
allowed?
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.
As said, I always forget the leading dot.
# | ||
# - `use`: Whether to use constrained_layout. Default is False | ||
# - `w_pad`, `h_pad` Padding around axes objects. | ||
# - *use*: Whether to use constrained_layout. Default is False |
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.
I would tend to use double backticks. But don't really care too much here.
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.
You're right, one should be consistent. Double backticks probably make it clearer that this is some code that is entered somewhere.
# to `ax.set_position()` will set the axes so constrained_layout has no | ||
# effect on it anymore. (Note that constrained_layout still leaves the space | ||
# for the axes that is moved). | ||
# to `~.axes.Axes.set_position()` will set the axes so constrained_layout has |
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.
see above.
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.
Second most often error. Forget to remove brackets.
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.
I think brackets are allowed. I was questioning the ~.axes
part because I did not realize the wildcard import in axes
.
# In the code, this is accomplished by the entries in `.do_constrained_layout` | ||
# like:: | ||
# In the code, this is accomplished by the entries in | ||
# ``.do_constrained_layout`` like:: |
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.
Either no leading dot (and possibly trailing parentheses) or a proper link.
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.
Cannot link to it, because that is a method from a private module which does not occur inside the docs. One may ask in general why all those methods are exposed here, while not being documented, but there might be a reason, so I'm not cutting this part.
@@ -589,7 +606,7 @@ def docomplicated(suptitle=None): | |||
# much smaller than the left-hand, so the right-hand layoutboxes are smaller. | |||
# | |||
# The Subplotspec boxes are laid out in the code in the subroutine | |||
# `.arange_subplotspecs`, which simply checks the subplotspecs in the code | |||
# ``.arange_subplotspecs``, which simply checks the subplotspecs in the code |
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.
Either no leading dot (and possibly trailing parentheses) or a proper link.
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.
This is the method or function that does not even exists. Maybe @jklymak can comment here and in the cases below how this is to be understood and how those names are in general to be layouted. Maybe there is a deeper sense in the leading-dot-notation here?
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.
I assume that it was thought to be a link. `.arange_subplotspecs`
would be perfectly fine if the module wasn't private.
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.
Oh stupid, of course you're right. Will change that.
@@ -627,9 +644,9 @@ def docomplicated(suptitle=None): | |||
# number of columns (one in this example). | |||
# | |||
# The colorbar layout logic is contained in `~matplotlib.colorbar.make_axes` | |||
# which calls `._constrained_layout.layoutcolorbarsingle` | |||
# which calls ``._constrained_layout.layoutcolorbarsingle`` |
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.
No leading dot (and possibly trailing parentheses).
# for cbars attached to a single axes, and | ||
# `._constrained_layout.layoutcolorbargridspec` if the colorbar is associated | ||
# ``._constrained_layout.layoutcolorbargridspec`` if the colorbar is associated |
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.
No leading dot (and possibly trailing parentheses).
@@ -713,7 +730,7 @@ def docomplicated(suptitle=None): | |||
# the axes position in made the same size as the occupied Axes positions. | |||
# | |||
# This is done at the start of | |||
# `~._constrained_layout.do_constrained_layout` (``hassubplotspec``). | |||
# ``~._constrained_layout.do_constrained_layout`` (``hassubplotspec``). |
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.
No leading dot (and possibly trailing parentheses).
6396b50
to
79873aa
Compare
I’m at a meeting and can’t work on this. If you guys think it’s an improvement I’m all for it. Often the person who wrote the first draft shouldn’t write the second. OTOH happy to try to help if any technical questions. But if none feel free to merge w/o me! |
From my side this is "fixed" and can be merged as is. But I think in the long run, the lower part of this guide could benefit from being proof-read by you again. Possibly this is all fine, but I sure lack the expertise to know. What makes me wonder is that it refers to a function that does not exist and in general explains stuff that you cannot understand without deeply inspecting the private module itself. |
79873aa
to
553bfab
Compare
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.
Thanks a lot!
PR Summary
It wasn't clear to me that constrained_layout needs to be activated before adding any subplots to a figure. I find this an important piece of information and added it in the constrained layout guide. Also see minimal discussion on gitter.
While doings so, I also improved some other parts of this guide, mainly adding or fixing links/references.
When reading I came across a function
.arange_subplotspecs
which seems to not exist anywhere in the code base. Suggestions on how to change that could still be incoorporated here.attn. @jklymak (who wrote that guide and should hence be the expert to review this.)
PR Checklist