Skip to content

DOC: add a couple more placement examples, crosslink axes_grid [ci doc] #26914

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
Sep 27, 2023

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Sep 25, 2023

Noted in SciTools/cartopy#2248 (comment) - placing colorbars inside axes is sometimes a good thing to do (think a map, where you know you have no data coloured over a body of water, so the colorbar fits nicely there). This adds a couple of simple examples to show how to do that. Also crosslink from demo-colorbar-with-inset-locator and demo-colorbar-with-axes-divider and added some notes that these methods can typically be accomplished by easier means.

@jklymak jklymak force-pushed the doc-manual-colorbars branch 5 times, most recently from 1115c7f to 3ca96ad Compare September 25, 2023 21:45
@jklymak jklymak marked this pull request as ready for review September 25, 2023 22:51
@jklymak jklymak requested a review from rcomer September 25, 2023 22:52
Copy link
Member

@rcomer rcomer left a comment

Choose a reason for hiding this comment

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

The new examples look good to me.


# %%
# Manually placing colorbars
# ==========================
Copy link
Member

@rcomer rcomer Sep 26, 2023

Choose a reason for hiding this comment

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

I wonder if this and the previous section should be two subsections under this title, since in both we are encouraging the user to do it manually.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I rearranged somewhat. Need to see how it looks before I decide where to link


Inset axes placement is controlled as for legends: either by providing a *loc*
option ("upper right", "best", ...), or by providing a locator with respect to
the parent bbox. Parameters such as *bbox_to_anchor* and *borderpad* likewise
work in the same way, and are also demonstrated here.

Users should consider using `.Axes.inset_axes` instead (see
:ref:`colorbar_placement`).
Copy link
Member

Choose a reason for hiding this comment

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

If the last two sections of the colorbar guide become one "Manually Placing Colorbars" section (see other comment), then this could link directly to that.

@jklymak jklymak force-pushed the doc-manual-colorbars branch from 08926c5 to c234384 Compare September 26, 2023 16:50
@jklymak jklymak marked this pull request as draft September 26, 2023 16:54
@jklymak jklymak force-pushed the doc-manual-colorbars branch from c234384 to 4f75570 Compare September 26, 2023 17:42
@jklymak jklymak marked this pull request as ready for review September 26, 2023 18:17
fig.colorbar(pcm, ax=axs[1], shrink=0.6)

# %%
# This is usual undesired, and can be worked around in various ways, e.g.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# This is usual undesired, and can be worked around in various ways, e.g.
# This is usually undesired, and can be worked around in various ways, e.g.

Comment on lines 13 to 14
Automatic placement
===================
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Automatic placement
===================
Automatic placement of colorbars
================================

For consistency with the "Manual" section below. Or make the other title short to match this, but I think the longer titles would be better if other parts of the docs link to specific sections?

# :ref:`axes_grid` has methods for creating colorbar axes as well:
#
# - :ref:`demo-colorbar-with-inset-locator`
# - :ref:`demo-colorbar-with-axes-divider`
Copy link
Member

Choose a reason for hiding this comment

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

Think the "see also" should be at the bottom of the page?

Comment on lines 171 to 173
# We solve this problem using `.Axes.inset_axes` to locate the axes in axes
# coordinates. Note that if you zoom in on the axes, and thus
# change the shape of the axes, the colorbar will also change position.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# We solve this problem using `.Axes.inset_axes` to locate the axes in axes
# coordinates. Note that if you zoom in on the axes, and thus
# change the shape of the axes, the colorbar will also change position.
# We solve this problem using `.Axes.inset_axes` to locate the colorbar relative to the
# parent axes. Note that if you zoom in on the parent axes, and thus
# change the shape of it, the colorbar will also change position.

I appreciate this paragraph isn't new, but I feel like there are too many "axes" in there and it could be more specific about which axes each one refers to...!

Copy link
Member Author

Choose a reason for hiding this comment

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

Went with the similar with a link out to the jargon:

# We solve this problem using `.Axes.inset_axes` to locate the axes in "axes
# coordinates" (see :ref:`transforms_tutorial`).  Note that if you zoom in on
# the parent axes, and thus change the shape of it, the colorbar will also
# change position.

@jklymak jklymak force-pushed the doc-manual-colorbars branch 2 times, most recently from 3ca0e25 to fdf1f25 Compare September 27, 2023 14:13
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
@jklymak jklymak force-pushed the doc-manual-colorbars branch from fdf1f25 to ab94dd7 Compare September 27, 2023 14:17
Copy link
Member

@rcomer rcomer 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 to me.

@rcomer rcomer added this to the v3.8-doc milestone Sep 27, 2023
@rcomer rcomer merged commit 37426df into matplotlib:main Sep 27, 2023
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 27, 2023
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 27, 2023
rcomer added a commit that referenced this pull request Sep 27, 2023
…914-on-v3.8.0-doc

Backport PR #26914 on branch v3.8.0-doc (DOC: add a couple more placement examples, crosslink axes_grid [ci doc])
rcomer added a commit that referenced this pull request Sep 27, 2023
…914-on-v3.8.x

Backport PR #26914 on branch v3.8.x (DOC: add a couple more placement examples, crosslink axes_grid [ci doc])
@ksunden ksunden mentioned this pull request Nov 2, 2023
5 tasks
@jklymak jklymak deleted the doc-manual-colorbars branch January 4, 2024 00:45
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.

2 participants