Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add _repr_png_ and _repr_html_ to Colormap objects.#17888

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
tacaswell merged 7 commits intomatplotlib:masterfrombdice:colormap-repr
Jul 12, 2020

Conversation

bdice
Copy link
Contributor

@bdicebdice commentedJul 11, 2020
edited
Loading

PR Summary

This PR adds_repr_png_ and_repr_html_ methods to thematplotlib.colors.Colormap class, enabling visual representations ofColormap objects in IPython / Jupyter settings.

Demo

image

Resolves#15616.

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/next_api_changes/* if API changed in a backward-incompatible way

@bdicebdice marked this pull request as ready for reviewJuly 11, 2020 17:49
Copy link
Contributor

@dopplershiftdopplershift 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 pending CI passing

@dopplershiftdopplershift added this to thev3.4.0 milestoneJul 11, 2020
@dopplershift
Copy link
Contributor

dopplershift commentedJul 11, 2020
edited
Loading

This is going to be really awesome for our notebook users. I'll be sure to feature it in the workshops I teach.

bdice and story645 reacted with heart emoji

Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

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

Better tests are always better, but I'm also 👍 in with any level of testing.

@QuLogic
Copy link
Member

For the PNG, I guess this is okay. However, colormaps have some other options like bad/over/under colors, which I think we could also insert into the HTML repr.

bdice reacted with thumbs up emoji

@jklymak
Copy link
Member

... good point - extend='both' would be a nice addition....

@tacaswell
Copy link
Member

I am happy to bank this improvement and then sort out how to handle the over / under / bad.

@story645 suggested something likef'{name} (over {html rect of over color} | under {html rect of under color} | bad {html rect of bad color}'

timhoffm and bdice reacted with thumbs up emoji

@tacaswell
Copy link
Member

Spoke with@bdice on audio. Because we don't currently have public api to get the under/over/bad values I am going to merge this PR as-is and@bdice we open a new PR addingget_* methods and adding them to the html repr.

@jklymak
Copy link
Member

I guess I'm somewhat leery about this. Is there some reason this doesn't just create a colorbar and then fill the png with that? You won't get the over under w/o the colorbar logic anyhow. It would also be nice if the repr had an axes either going from 0-1 or from 0-N where N is the number of colours.

@tacaswell
Copy link
Member

I suggested to go down this route of direct PNG generation to get the simplest possible code to get a visual representation of the colormap. We already have a hard dependency on pillow so this seems way simpler than going through making a figure -> colorbar -> save it. I also think the split here between the png repr (just the color ramp) and the html (colorramp + metadata) so it will play nicely with some lower-fidelity UI (like terminals that can display png).

I do not think that the tick labels are particularly useful (we don't show them inhttps://matplotlib.org/3.2.2/tutorials/colors/colormaps.html) because we only want to show the gamut.

As for adding information to the html repr we should move that discussion to#17900

I'm going to go ahead and merge this (despite@jklymak 's concerns) because this is definitely an improvement and all of the user feedback I have seen on this has been super positive.

@tacaswelltacaswell merged commit068e0f4 intomatplotlib:masterJul 12, 2020
@tacaswell
Copy link
Member

Congratulations on your first Matplotlib PR@bdice 🎉

bdice reacted with laugh emojibdice reacted with hooray emoji

@michaelosthege
Copy link

Really looking forward to this feature!

Question: Does this already deal with transparent colormaps? I recently had troubles establishing a custom colormap with transparency, because whenever I plotted it, the background in my notebook was white, so I couldn't tell if my transparency settings actually worked.

I ended up with this snippet, but it would be great if the_repr_html/_repr_png could just show a grey-checkered background.

x=numpy.arange(256)fig,ax=pyplot.subplots(figsize=(12,1))ax.scatter(x,numpy.ones_like(x)-0.01,s=100,c=[cmap_without_transparency(v)forvinx])ax.scatter(x,numpy.ones_like(x)+0.01,s=100,c=[cmap_with_transparency(v)forvinx])ax.set_ylim(0.9,1.1)pyplot.show()

@QuLogic
Copy link
Member

This is already available in 3.4.0. It does not do anything special for transparency.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm left review comments

@tacaswelltacaswelltacaswell approved these changes

@dopplershiftdopplershiftdopplershift approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.4.0
Development

Successfully merging this pull request may close these issues.

Colormaps should have a_repr_html_ that is an image of the colormap
7 participants
@bdice@dopplershift@QuLogic@jklymak@tacaswell@michaelosthege@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp