Skip to content
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

ENH: add to_grayscale() method to color maps #3589

Closed
wants to merge 1 commit into from

Conversation

jakevdp
Copy link
Contributor

@jakevdp jakevdp commented Sep 29, 2014

This PR adds a method to the Colormap base class which computes and returns a grayscale version of the map. This helps to quickly preview how various colormaps will appear when printed in grayscale.

This uses the same formula as photoshop's grayscale conversion; see http://alienryderflex.com/hsp.html for details.

As an example of the usage, we can quickly demonstrate one reason why everybody loves to rag on jet:

plt.figure(figsize=(8, 3))
im = np.random.rand(10, 10)

plt.subplot(121)
plt.imshow(im, cmap=plt.cm.jet)
plt.colorbar()

plt.subplot(122)
plt.imshow(im, cmap=plt.cm.jet.to_grayscale())
plt.colorbar()

jet_example

I'm open to any suggestions or comments! I'm not sure if there are any complications with corner cases that I might be overlooking...

@tacaswell tacaswell added this to the v1.5.x milestone Sep 29, 2014
@tacaswell
Copy link
Member

👍 looks good to me

@WeatherGod
Copy link
Member

I am -1 in its current form. I think it would be misleading to call it
"to_grayscale()" when we have a grayscale colormap. I am not sure I would
like to encourage users to do a direct grayscale conversion as opposed to
simply using the grayscale colormap. That said, I do think that the feature
you are trying to provide has merit. Indeed, the lack of this kind of
feature was one of my first frustration points with matplotlib. It would
have been a good teaching point to have then read the colormap
documentation that we now have.

Also, what about other grayscale conversions? Imagemagick has a good
introduction to the myriad of possible conversions:
http://www.imagemagick.org/Usage/color_mods/#grayscale

On Sun, Sep 28, 2014 at 10:49 PM, Thomas A Caswell <notifications@github.com

wrote:

[image: 👍] looks good to me


Reply to this email directly or view it on GitHub
#3589 (comment)
.

@mdboom
Copy link
Member

mdboom commented Sep 29, 2014

I think the approach in #3279 is preferable, since it converts everything in the image, not just colormapped items, to greyscale, and additionally adds some color-blindness-simulation transformations.

@jakevdp
Copy link
Contributor Author

jakevdp commented Sep 29, 2014

@WeatherGod – the point here is not to simply use a grayscale color map. The point is to see how your color figure will look if it is to be printed as black and white (and to provide an easy utility to show people how bad jet is)

I hadn't seen #3279, but I agree it's preferable to this approach.

@tacaswell
Copy link
Member

Closing this in favor of #3279 @jakevdp ping me if you disagree.

@tacaswell tacaswell closed this Oct 18, 2014
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.

None yet

4 participants