Skip to content

DOC: Clarify/simplify example of multiple images with one colorbar #28546

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 2 commits into from
Jul 31, 2024

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Jul 12, 2024

I've simplified the basic example to only share the norm. This should be sufficient for most users and greatly simplifies the code. Syncing the colorbar moved to a separate comment - for those wo need the extra functionality.

Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

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

Wondering if this should just be a stand alone example (dynamic cmap updating? ) with same colormap tag b/c it's a lot of information that applies in a specific use case. ETA: got cut off, but was talking about:

# %%
# The colors are now kept consistent across all images when changing the
# scaling, e.g. through zooming in the colorbar or via the "edit axis,
# curves and images parameters" GUI of the Qt backend.
#
# While the norm is shared, the colormaps are not. This is often ok
# because colormaps are usually not changed dynamically. However, a user
# could change the colormap of an individual image through the
# "edit axis, curves and images parameters" GUI of the Qt backend.
# Unlike with a norm, it does not help to share colormaps between images.
# Changes to the norm limits modify the norm object in place and thus
# propagate to all images. But changing a colormap sets a new colormap
# object to the images and thus does not propagate to the other images.
# To make all other images follow, you could additionally sync the
# colormaps using the following code::
#
#     def sync_cmaps(changed_image):
#         for im in images:
#         if changed_image.get_cmap() != im.get_cmap():
#             im.set_cmap(changed_image.get_cmap())
#
#     for im in images:
#         im.callbacks.connect('changed', sync_cmaps)

@timhoffm
Copy link
Member Author

timhoffm commented Jul 13, 2024

I believe that this is the right place to discuss cmap syncing.

  • The need for cmap syncing is quite rare because (1) you rarely change the colormap later. (2) I assume the Qt dialog is more or less the only way to change the colormap by an end-user without the possibility to intercept and handle this by the plot author (all other modifications likely have to go though some API provided by the author alongside the plot, which means they can be propagated actively to all images, without the need to monitor changes").
  • This is only meaningful as an extension to a shared norm. A separate example would have to completely include the code of this example first.
  • A seprate tile one the examples page does not help for visually finding the cmap syncing topic because you cannot illustrate cmap syncing in a static image.

I've made a subsection "Advanced: Additionally sync the colormap" to better set the context for this.

@timhoffm
Copy link
Member Author

Ping @story645. What do you think of my suggestion?

Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

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

So uh I now understand better why you want to leave that here and I'm OK w/ that, but I went back and read through the explanations and uh I think they may have accidentally ended up in enough detail to spur questions but not enough to answer em territory :/

@timhoffm timhoffm force-pushed the doc-multi-image branch 2 times, most recently from f199fd4 to a425afb Compare July 29, 2024 10:26
Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

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

Is definitely much much better than before, thank you so much! Comments mostly around the same implementation detail problem, which is how do we effectively communicate that norm instances can be shared but not cmap instances.

Am thinking maybe (and I understand if this is out of scope and should be a follow up PR) we write this once as the final section of choosing colormaps. Call it "Using colormaps across multiple plots" , have this explanation, and use it as the lead in to "why norms" since that's the next topic, and then just link to that section here.

Comment on lines 14 to 16
to explicitly ensure consistent data coloring. The most important aspect
is the data normalization. By explicitly creating a norm and using that
for all images, we ensure that all images are scaled consistently.
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
to explicitly ensure consistent data coloring. The most important aspect
is the data normalization. By explicitly creating a norm and using that
for all images, we ensure that all images are scaled consistently.
to explicitly ensure consistent data coloring by using the same data normalization (data scaling) method for all the images. We ensure that same method is used by explicitly creating a *norm* object that we pass to all the image plotting methods.

Comment on lines +48 to +49
# curves and images parameters" GUI of the Qt backend. This is sufficient
# for most practical use cases.
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
# curves and images parameters" GUI of the Qt backend. This is sufficient
# for most practical use cases.
# curves and images parameters" GUI of the Qt backend.

Folks will tell us if it's sufficient?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see this as guidance and affirmation that most users can stop here. They don't have to inverst the following extra effort for cmap handling.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, maybe "this is" is just ambiguous pronoun reference then.

@timhoffm
Copy link
Member Author

timhoffm commented Jul 30, 2024

I've rewritten the paragraph on cmap sharing again. Focussing on the main point: Scaling changes the norm in place, but change of colormap changes the referenced colormap. Therefore sharing a colormap does not help and you need a different syncing mechanism.

Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

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

Slight wording nits but this is really clear now, thanks! Take/leave nits and can self merge

Comment on lines +48 to +49
# curves and images parameters" GUI of the Qt backend. This is sufficient
# for most practical use cases.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, maybe "this is" is just ambiguous pronoun reference then.

@timhoffm timhoffm merged commit f7b3def into matplotlib:main Jul 31, 2024
19 checks passed
@timhoffm timhoffm deleted the doc-multi-image branch July 31, 2024 04:34
@QuLogic QuLogic added this to the v3.10.0 milestone Jul 31, 2024
@timhoffm
Copy link
Member Author

timhoffm commented Aug 5, 2024

@meeseeksdev backport to v.3.9.x

@timhoffm
Copy link
Member Author

timhoffm commented Aug 5, 2024

I'm backporting so that this version gets into released docs. It may be that this will be changed agian for 3.10 because of the upocoming Colorizer changes. I want to make sure, this improved old-style method is kept publically available through 3.9 docs.

Copy link

lumberbot-app bot commented Aug 5, 2024

Something went wrong ... Please have a look at my logs.

It seems that the branch you are trying to backport to does not exist.

@timhoffm
Copy link
Member Author

timhoffm commented Aug 5, 2024

@meeseeksdev backport to v3.9.x

timhoffm added a commit that referenced this pull request Aug 5, 2024
…546-on-v3.9.x

Backport PR #28546 on branch v3.9.x (DOC: Clarify/simplify example of multiple images with one colorbar)
@timhoffm
Copy link
Member Author

timhoffm commented Aug 5, 2024

@meeseeksdev backport to v3.9.1-doc

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Aug 5, 2024
timhoffm added a commit that referenced this pull request Aug 5, 2024
…546-on-v3.9.1-doc

Backport PR #28546 on branch v3.9.1-doc (DOC: Clarify/simplify example of multiple images with one colorbar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation: examples files in galleries/examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants