8000 Wishlist: Multidimensional colormaps · Issue #4369 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Wishlist: Multidimensional colormaps #4369

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

Closed
ischwabacher opened this issue Apr 22, 2015 · 13 comments
Closed

Wishlist: Multidimensional colormaps #4369

ischwabacher opened this issue Apr 22, 2015 · 13 comments

Comments

@ischwabacher
Copy link
Contributor

xref #3343

TL;DR: It would be nice if it were possible to have color maps for multidimensional data, instead of expecting the color to depend only on a single quantity as is currently the case.

I'm currently working on an application that would like to be able to modulate the color and opacity of an image independently (as in Figure 3.B.b of Allen et al. 2012) so that color indicates a parameter estimate and opacity indicates a statistic assessing the reliability of that estimate:

Allen et al. 2012, Fig. 3

Currently, this must be accomplished by applying a color map to the parameter estimate, then overwriting the alpha channel with the statistical map, and finally calling imshow with the computed RGBA data. (This is what @mwaskom is doing in the referenced issue.) This is a nuisance, and more importantly, it forces all interpolation to be done in RGBA space instead of in data space (xref #5490).

Rather than simply making it possible to control alpha independently of RGB, it would make sense to allow color maps that map multidimensional data to RGBA space. Then imshow's color map for 3-dimensional input can default to id ⊕ 1, and for 4-dimensional input to id, which gets rid of those special cases and makes it possible to have other color maps of those dimensionalities.

One could imagine other use cases for this in neuroimaging; for instance, diffusion tensor images are commonly displayed with hue depending on the principal eigenvector of a symmetric tensor field, while luminosity depends on the dispersion of the eigenvalues.

Diffusion Tensor image

In a completely different direction, one could display a complex-valued function by splitting the complex data into real and imaginary parts, and then applying a two-dimensional color map that sets hue based on the argument and luminosity based on the modulus of the input:

The Jacobi theta function

@tacaswell tacaswell added this to the proposed next point release milestone Apr 22, 2015
@tacaswell
Copy link
Member

All sounds great to me. I see no technical issue, it is just a matter of someone doing this.

If we only want to map 2D data -> r 8000 gba than I think a family of normalizers which go from data -> unit-disk (or is unit square more sensible) in the complex plane and then color maps that go from the unit disk -> RGBA would be a good start.

If we want to do higher dimensions map to quaternions (or maybe that is getting too fancy?).

@OceanWolf
Copy link
Member

I guess though we shouldn't limit ourselves to 2d colour spaces.

Thinking of colour spaces, have you heard of the L_a_b* colour space? http://en.wikipedia.org/wiki/Lab_color_space as it "aspires to perceptual uniformity" I wonder if this could help influence our choice of colourmaps for our colour revolution...

@OceanWolf
Copy link
Member

Some other related issues:

  • The documentation on imshow says "MxN – luminance (grayscale, float array only)" even though it doesn't relate to luminance, it maps the value to the (specified/default) colourmap.
  • When we plot a MxNx3 and MxNx4 array, we can still add a colorbar despite it having no meaning to the data.
import numpy as np
import matplotlib.pyplot as plt

data = np.random.rand(6,5,3)
plt.imshow(data, interpolation='none')
plt.colorbar()
plt.show()

If we wanted to plot multi-dimensional colormaps then I guess we need to change the colorbar implementation as well to deal with this...

@tacaswell
Copy link
Member

The 'luminescence' in this case is a synonym for monochrome (which coming from a light microscopy background means luminescence on the detector side) so the documentation is fine.

@endolith
Copy link
Contributor
endolith commented Feb 20, 2016

See also discussion on Stack Overflow.

and then applying a two-dimensional color map that sets hue based on the argument and luminosity based on the modulus of the input:

I've been doing this "by hand" in Lab space with mpmath.cplot, which takes a function to generate the RGB color from the amplitude and phase of each pixel (but is extremely slow):

5th order Bessel filter

Actually this is using colorspacious now, and it's cylindrical coordinates, so "Jch space"?

Edit: this is now at https://github.com/endolith/complex_colormap

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
@sbenthall
Copy link

+1 wanting this feature.

@efiring
Copy link
Member
efiring commented Aug 10, 2020

@njsmith, since this involves color spaces and targets neuroscience, perhaps among other applications, do you have some advice?

@efiring
Copy link
Member
efiring commented Aug 10, 2020

The simplest version of this, via control of alpha, is being revived in #6268.
My suspicion is that perhaps anything beyond this should be handled as a separate package that pre-processes the inputs and returns RGBA image or QuadMesh arrays for display by matplotlib's existing functionality, or that invokes that functionality directly.

@arshadpatel2001
Copy link

Hey, is anyone working on this?
If not I would like to contribute towards the same And would like to know more about it, and how I can get started?

@OceanWolf
Copy link
Member

@arshadpatel2001 Have you taken a look at the repository of @endolith posted above, that sounds like a good first step. I don't know if we need to extend the concept of perceptually-uniform to 2d, i.e. if so maybe we take the | grad C | to create a perceptual scalar field?

Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Mar 11, 2024
@QuLogic QuLogic added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Mar 11, 2024
@story645
Copy link
Member

This is essentially being worked on as part of the colormapping work started in #28658

@timhoffm
Copy link
Member

Tracked in #14168, and worked on in #28658, #28454, #29221.

@QuLogic QuLogic removed the keep Items to be ignored by the “Stale” Github Action label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0