Skip to content

Color scale midpoint #3509

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
nicolaskruchten opened this issue Feb 4, 2019 · 5 comments
Closed

Color scale midpoint #3509

nicolaskruchten opened this issue Feb 4, 2019 · 5 comments
Labels
feature something new

Comments

@nicolaskruchten
Copy link
Contributor

Right now to use a diverging color scale, the user has to do some math outside of plotly.js to ensure that the midpoint is at an appropriate value in data-space. This math is actually almost impossible to do in the case of histogram2d as the data values are computed within plotly.js... I propose a new attribute cmid (or zmid as appropriate) which would make this easier.

If mid is provided and neither min nor max then after the existing automatic computation, whichever of those two is closest to the midpoint will be pushed away by an appropriate amount. If either min or max is provided but not both, then the unspecified one will be set at a distance from mid equal to the distance of the specified one. If both min and max are provided, this setting does nothing.

Feedback before I start implementing?

@archmoj
Copy link
Contributor

archmoj commented Feb 4, 2019

It may be useful if in addition to mid value (or instead) one could select a function (e.g. log) to describe how the values are mapped between 'min' and 'max'.

@nicolaskruchten
Copy link
Contributor Author

@archmoj I think this is orthogonal to this particular feature. Right now we handle linear interpolation, and auto-computation of bounds, and this proposal is a small refinement on this. We could/should also handle log colorscales with a separate boolean flag, but I'm not sure what the value-added would be of doing something substantially more generic... do you have any specific examples in mind?

@archmoj
Copy link
Contributor

archmoj commented Feb 5, 2019

Totally agree.
Here is an example.

@etpinard
Copy link
Contributor

etpinard commented Feb 6, 2019

Interesting idea. I remember at some point thinking about turning cmin / cmax into a 2-item array crange to be more consistent with axis range. I'm not sure how cmid would fit in, if we choose to switch to crange?

Moreover, perhaps we could add rangemode: 'symmetric' for color scales (similar here too to data axes) That said, cmid is more general.

@nicolaskruchten
Copy link
Contributor Author

Certainly I think that the most common value for cmid would be 0, but it would be good to have the more-general version. If/when we switch to crange, I could easily see that alongside cmid... Not sure what the downside is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

No branches or pull requests

3 participants