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

Skip to content

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

Conversation

ImportanceOfBeingErnest
Copy link
Member

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

  • Documentation is sphinx and numpydoc compliant

Copy link
Member

@timhoffm timhoffm left a 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``
Copy link
Member

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 ...

Copy link
Member Author

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__

Copy link
Member

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.
Copy link
Member

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)

Copy link
Member Author

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
Copy link
Member

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?

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

Choose a reason for hiding this comment

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

see above.

Copy link
Member Author

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.

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 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::
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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``
Copy link
Member

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
Copy link
Member

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``).
Copy link
Member

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).

@ImportanceOfBeingErnest ImportanceOfBeingErnest force-pushed the doc_constrained_layout_improvement branch 2 times, most recently from 6396b50 to 79873aa Compare June 6, 2018 21:17
@jklymak
Copy link
Member

jklymak commented Jun 6, 2018

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!

@ImportanceOfBeingErnest
Copy link
Member Author

ImportanceOfBeingErnest commented Jun 6, 2018

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.

@ImportanceOfBeingErnest ImportanceOfBeingErnest force-pushed the doc_constrained_layout_improvement branch from 79873aa to 553bfab Compare June 7, 2018 20:50
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@jklymak jklymak merged commit 9d81809 into matplotlib:master Jun 9, 2018
@ImportanceOfBeingErnest ImportanceOfBeingErnest deleted the doc_constrained_layout_improvement branch June 15, 2018 00:35
@QuLogic QuLogic added this to the v3.0.0 milestone Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants