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

Skip to content

DOC: Update interactive colormap example #21236

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
Oct 2, 2021

Conversation

greglucas
Copy link
Contributor

PR Summary

The colormaps have interactivity with zoom/pan now, so demonstrate what those modes do with this new example. This is instead of using callbacks and mouse events for updates that were used in the previous example.

Example modified from: #19515 (comment)

xref: #19515 and #20471

PR Checklist

  • [N/A] Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@greglucas greglucas added this to the v3.5.0 milestone Sep 30, 2021
Comment on lines 33 to 42
zoom_axes = ["2d", "color zoom in", "color zoom out"]
pan_axes = ["2d", "color pan up", "color pan down"]

fig, ax_dict = plt.subplot_mosaic(
[
zoom_axes,
pan_axes
],
constrained_layout=True,
)
Copy link
Member

Choose a reason for hiding this comment

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

I find the multitude of axes rather confusing. AFAICS they only differ in their initial clim values. I assume that's intended to give a good starting point for the respective interactions. However, all operation work reasonably well when starting on the "2d" image. It think it's better to have only the one image and let the user try all operations on that image.

I also found that panning on the image was really slow, likely because varying tick labels cause the constrained_layout solver to kick in again. One would have to deactivate constrained_layout after the first draw. But that's also obsolete if we can get away with one image.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 The reason for that was to demonstrate what the outcome of zooming/panning would do in each of the cases, but perhaps you're right it would be better to just let someone start interacting with the image and see for themselves. I updated this to have 3 images now with data ranges that are under/normal/over to try and get the sense that you can interact with the colorbar to identify new data regions.

Let me know what you think of this approach... Happy to go to just 1 image as well if you think that would be more clear.

@jklymak jklymak modified the milestones: v3.5.0, v3.5.1 Oct 1, 2021
@greglucas greglucas force-pushed the cmap-interactive-example branch from 68cbc97 to b01d5c6 Compare October 1, 2021 14:24
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.

I think this would be enough:

fig, ax = plt.subplots()
im = ax.imshow(data2d)
fig.colorbar(im, ax=ax)
ax.set_title('Pan on the colorbar to shift the mapping data -> color\nZoom on the colorbar to scale the mapping data -> color ')
plt.show()

grafik

Since the gallery is static by nature, we simply cannot show interactivity. IMHO the best we can do is to have a simple example and tell the readers what they should try themselves.

If you really want to do more, I suggest to show some example images additionally:

  • This is the result after shifting the colorbar scale up: [image]
  • This is the result of zooming in: [image]
  • This is the result of zooming out: [image]
    Maybe even use the image directive to hide the code, because having code that produces the same result as your interactivity is rather confusing.

@greglucas greglucas force-pushed the cmap-interactive-example branch from b01d5c6 to adace6d Compare October 1, 2021 22:12
@greglucas
Copy link
Contributor Author

OK, I went with your suggestion to keep it simple. I changed "mapping data -> color" to "norm" as that seems easier to read.

I agree that it is tough to demonstrate interactivity, and I'm not sure how many people even know all of the options for interactivity! I know I personally keep learning new things just by stumbling upon them. Perhaps a solution could be to add a tutorial page with some screen recorded gifs of people using the interactive features...

@timhoffm
Copy link
Member

timhoffm commented Oct 1, 2021

I changed "mapping data -> color" to "norm" as that seems easier to read.

While technically correct, "norm" requires at least mid-level knowledge of Matplotlib. Users only using imshow(..., vmin= ..., vmax=...) likely won't know what a "norm" is. Can we find a phrase that's also understandable for inexperienced users? Maybe "... to shift the color mapping"? (somewhat imprecise, but I think ti would get the idea across).

Perhaps a solution could be to add a tutorial page with some screen recorded gifs of people using the interactive features...

That'd be a really cool thing 😀

The colormaps have interactivity with zoom/pan now, so demonstrate
what those modes do with the new example. This is instead of using
callbacks and mouse events for updates.
@greglucas greglucas force-pushed the cmap-interactive-example branch from adace6d to 2e7a052 Compare October 1, 2021 22:56
@timhoffm timhoffm modified the milestones: v3.5.1, v3.5.0 Oct 2, 2021
@timhoffm timhoffm merged commit 5431e38 into matplotlib:master Oct 2, 2021
@lumberbot-app
Copy link

lumberbot-app bot commented Oct 2, 2021

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.5.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 5431e3888db24e57a4856d14fca9eb2d065cfd53
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #21236: DOC: Update interactive colormap example'
  1. Push to a named branch :
git push YOURFORK v3.5.x:auto-backport-of-pr-21236-on-v3.5.x
  1. Create a PR against branch v3.5.x, I would have named this PR:

"Backport PR #21236 on branch v3.5.x (DOC: Update interactive colormap example)"

And apply the correct labels and milestones.

Congratulation you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove Still Needs Manual Backport label once the PR gets merged.

If these instruction are inaccurate, feel free to suggest an improvement.

greglucas pushed a commit to greglucas/matplotlib that referenced this pull request Oct 2, 2021
@greglucas greglucas deleted the cmap-interactive-example branch October 2, 2021 14:01
timhoffm added a commit that referenced this pull request Oct 3, 2021
…on-v3.5.x

Backport PR #21236: DOC: Update interactive colormap example
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Oct 12, 2021
…xample

DOC: Update interactive colormap example
tacaswell pushed a commit that referenced this pull request Oct 20, 2021
DOC: Update interactive colormap example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants