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

Colormap norming #122

Open
banesullivan opened this issue Mar 12, 2019 · 6 comments
Open

Colormap norming #122

banesullivan opened this issue Mar 12, 2019 · 6 comments
Labels
feature-request Please add this cool feature! help-wanted SOS - we need help on this one! partially-solved For issues that have been addressed but not solved

Comments

@banesullivan
Copy link
Member

banesullivan commented Mar 12, 2019

Color mapping and scalar bar feature requests:

These requests stemmed from conversations with @prisae and @craigmillernz

Custom Colormaps

Can we implement a way for a user to make custom colormaps using matplotlib and send that map as the cmap argument? This should be as simple as adding in a type check and skipping over the colormap lookup code.

Update: implemented in #126

Categorical Colormaps

We also need a way to have categorical colormaps

Update: this is possible by using a custom built colormap from matplotlib

norm option

Also, could we add a new norm keyword argument similar to matplotlib? See this page. This would help users apply a standard matplotlib norm or center a color mapping around a value without changing the range. E.g "My data scale goes from -0.6 to 0.3 and I'd like the red/blue color map to be centered so that white is at 0."

@craigmillernz provided a super useful function for implementing this type of norm:

#Class to normalize colors to center around a value
from matplotlib.colors import Normalize

class MidpointNormalize(Normalize):
    def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
        self.midpoint = midpoint
        Normalize.__init__(self, vmin, vmax, clip)

    def __call__(self, value, clip=None):
        # I'm ignoring masked values and all kinds of edge cases to make a
        # simple example...
        x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
        return np.ma.masked_array(np.interp(value, x, y))

Interactive colormaps

Could we maybe make a tool to create custom colormaps? This honestly might make the most sense to create a totally separate module under @OpenGeoVis. I'm thinking some sort of ipywidget or PyQt5 type interface where a user can harness to create a custom colormap. If we can get this going, then provide a way for it to like with vtki and update the mappers so a user can interactively update the rendering scene while changing the colormap.

Here is an example from @prisae in MatLab:

Peek 2019-03-11 09-00

@banesullivan banesullivan added the feature-request Please add this cool feature! label Mar 12, 2019
@prisae
Copy link
Member

prisae commented Mar 12, 2019

Thanks for opening the issue. As I mentioned on Slack, the idea arose because you mentioned the interactive keyword, which I meant was about changing the colormap, but turned out to be about changing the appearance/location of the colorbar. Again as I said before, I think in general this is a bad idea (at least for static figures, for the exactly same reasons why jet etc are bad colormaps), but it can be very useful to explore the dataspace interactively.

@banesullivan
Copy link
Member Author

I like the idea of having an interactive way of exploring the colormap and I think this might be a cool side project we could implement for simply creating a matplotlib colormap which we could support linking to vtki plots.

Perhaps we could make a new module called icolormap under @OpenGeoVis?

@prisae
Copy link
Member

prisae commented Mar 12, 2019

Maybe @mycarta, @kwinkunks has experienced already with something similar, maybe some stuff already exists?

They, quite rightly and as I do, tell everyone to use good colormaps. But by doing so, I think they've come along many tools, which might help here. As important as good colormaps are for static figures, I think such an interactive colormap could be very interesting indeed for playing around interactively.

@prisae
Copy link
Member

prisae commented Mar 12, 2019

(The dangers of it are obvious and known. In the Oil & Gas company I worked years ago it was common that we presented an EM inversion result, just so that the commercial managers came over to play around with the colour-bar [not Matlab, but similar feature] until they were satisfied with what they saw. But then, every powerful tool has its dangers if it falls into the wrong hands.)

@prisae
Copy link
Member

prisae commented Mar 15, 2019

LogNorm and SymLogNorm

Another point (along comments by @craigmillernz): Adding the possibility for LogNorm and SymLogNorm (as in matplotlib/discretize).

@banesullivan banesullivan added this to the 0.18.0 milestone Mar 21, 2019
@banesullivan banesullivan modified the milestones: 0.18.0, 0.18.1 Apr 11, 2019
@banesullivan banesullivan pinned this issue Apr 15, 2019
@banesullivan banesullivan unpinned this issue Apr 15, 2019
@banesullivan banesullivan added the help-wanted SOS - we need help on this one! label Apr 30, 2019
@banesullivan banesullivan removed this from the 0.20.2 milestone Jun 27, 2019
@banesullivan banesullivan added the partially-solved For issues that have been addressed but not solved label Jul 11, 2019
@banesullivan banesullivan changed the title Custom colormaps and interactive scalar bars Colormap norming Oct 31, 2019
@banesullivan banesullivan modified the milestone: 0.23.0 Nov 1, 2019
@e-dub
Copy link

e-dub commented Feb 23, 2021

I tried to implement the class MidpointNormalize ad hoc to center the color bar, alas without success. Did you get this to work or just an analogy to be implemented? Or has anyone found another solution to this?

I implemented another method adapted from here, but it weighs the smaller values too much, see figure.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Please add this cool feature! help-wanted SOS - we need help on this one! partially-solved For issues that have been addressed but not solved
Projects
None yet
Development

No branches or pull requests

3 participants