Skip to content

Shared colorscales/colorbars aka coloraxes #3431

Description

@nicolaskruchten

Right now traces can share axes but not colorbars. It would be nice if they could, something like data[].coloraxis = "color1" with layout.coloraxis1 = { ... } and all bounds-computations could include the union of the data of the traces, etc

Activity

  1. changed the title [-]Shared colorscales/colorbars[/-] [+]Shared colorscales/colorbars aka coloraxes[/+] on Feb 20, 2019
  2. self-assigned this
    on Apr 4, 2019
  3. added this to the v1.48.0 milestone on Apr 11, 2019
  4. etpinard commented on Apr 17, 2019

    @etpinard
    Contributor

    Quick question:

    What should happen when traces that don't have the same colorbar visuals (e.g a heatmap and contour trace) share the same color axis?

    In JSON form, this would be something like:

    var data = [{
      type: 'heatmap',
      z: [[1,2,3], [2,3,3]],
      coloraxis: 'coloraxis'
    }, {
      type: 'contour',
      z: [[2,3,1], [2,4,0]]
      coloraxis: 'coloraxis'
    }]
    
    var layout = {
      // e.g. some optional color-axis settings
      coloraxis: {
          colorscale: 'Viridis'
      }
    }

    then should we show two colorbars? A "combined" version (not sure how this would look like)? Maybe we could show a colorbar only if all traces have compatible color bar visuals? Or should color axes not have control over color bars at all? In other words, traces with the same coloraxis would share cmin / cmax / cmid and colorscale values - it would up the user to set showscale and the colorbar options accordingly in their trace(s).

  5. nicolaskruchten commented on Apr 17, 2019

    @nicolaskruchten
    ContributorAuthor

    Could we unify these color scales with a new attr like “discrete” or something? And then they could share

  6. nicolaskruchten commented on Apr 17, 2019

    @nicolaskruchten
    ContributorAuthor

    To be clearer: “discrete” would default based on the first trace that shares it, so contour-only would default to discrete and heatmap-only would not, and mixed would default to the first one but be overrideable

  7. alexcjohnson commented on Apr 18, 2019

    @alexcjohnson
    Collaborator

    Contours with coloring: 'heatmap' would work just fine already - the colorbar would have lines on it for the contours I guess, which wouldn't match the heatmap, but that's probably OK. And contours with coloring: 'lines' (or 'none') I don't see any sense allowing to share a colorbar with heatmaps. So we're only talking about coloring: 'fills'. But since we have to exclude 'lines' and 'none' already, I'd argue for excluding 'fills' too - and only allow contours with coloring: 'heatmap' to share a scale with a heatmap - until we manage to do "discrete" right.

    FWIW "discrete" itself has two variants that we need to be careful about. The version used in contour plots defines data values at the edges of each color - where the contour lines are. Much of the time heatmaps (and choropleths, scatter marker colors...) with discrete colors don't do that kind of mapping, they simply have discrete data and they map a single value to a single color. As far as the colorbar is concerned the main distinction is where the labels go: at the color boundaries vs midpoints. For the boundaries case we will need changes to trace rendering code, for the discrete data case we'll need changes to the colorbar rendering (and maybe trace rendering changes, if we want to also collapse multiple values onto one color)

  8. nicolaskruchten commented on Apr 18, 2019

    @nicolaskruchten
    ContributorAuthor
  9. alexcjohnson commented on Apr 18, 2019

    @alexcjohnson
    Collaborator

    it probably looks like rejecting that coloraxis value from the latter trace, and giving it a separate colorscale and bar.

  10. nicolaskruchten commented on Apr 18, 2019

    @nicolaskruchten
    ContributorAuthor

    Hmm. Is there any xaxis/yaxis precedent for this kind of rejecting? If two incompatible traces declare coloraxis: "coloraxis1" would we force a second color axis to exist and map one trace onto it, despite the figure spec?

  11. alexcjohnson commented on Apr 18, 2019

    @alexcjohnson
    Collaborator

    I feel like we do this in a bunch of situations, but one that comes to mind right now is scaleanchor, we'll ignore it if the referenced axis is the wrong type.

    If we reject a coloraxis setting, that trace would have no coloraxis so it would behave like all traces do right now - the trace defines its own colorscale and colorbar.

  12. nicolaskruchten commented on Apr 18, 2019

    @nicolaskruchten
    ContributorAuthor
  13. etpinard commented on Apr 29, 2019

    @etpinard
    Contributor

    done in #3803

  14. nicolaskruchten commented on Apr 29, 2019

    @nicolaskruchten
    ContributorAuthor

    Did we end up doing anything to move from cmin/cmax to range? It doesn't look like it... would this be a good time to introduce this? I.e. when using coloraxis you have to use range instead of cmin/cmax ?

  15. etpinard commented on Apr 29, 2019

    @etpinard
    Contributor

    Was that a requirement?

  16. nicolaskruchten commented on Apr 29, 2019

    @nicolaskruchten
    ContributorAuthor

    No, it was just something I remember talking about: #3549 (comment)

  17. etpinard commented on Apr 29, 2019

    @etpinard
    Contributor

    Ok, well if someone has a strong opinion on

    // the current
    layout.coloraxis.cmin / layout.coloraxis.cmax
    
    // vs
    layout.coloraxis.crange 
    
    // or vs
    layout.coloraxis.range
    

    you have about one week to speak up, before v1.48.0 is set for 🚀

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions