Skip to content

Contour plots with no colorscale should go in the legend #2880

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
alexcjohnson opened this issue Aug 7, 2018 · 3 comments
Closed

Contour plots with no colorscale should go in the legend #2880

alexcjohnson opened this issue Aug 7, 2018 · 3 comments
Labels
bug something broken feature something new

Comments

@alexcjohnson
Copy link
Collaborator

... and even contour plots with a colorscale might want to be in the legend instead of a colorbar.

Consider this plot with 3 overlaid contour traces: https://codepen.io/alexcjohnson/pen/oMazOJ?editors=0010
screen shot 2018-08-07 at 2 33 08 pm

The blue constraint-type trace shows up in the legend, as it should.

But the red trace doesn't show up in the legend OR in a colorbar (@phxnsharp I'm curious, how did you get a colorbar to appear in this case? Did you make a fake colorscale like [[0, 'red'], [1, 'red']]? When coloring='none' we currently don't even allow a colorbar)

And the black-and-white trace, despite the fact that it does have a colorscale, the user may prefer to show it in the legend anyway, especially when the levels are already labeled on the plot itself, but also so that in plots like this with many overlaid traces you can use the legend to hide it. The legend entry could either just show the line (which has a single color), or perhaps for consistency we fill below either using the middle color or with a gradient showing the whole colorscale.

Finally, if we have a colorbar and a legend on the same plot, it would be great if there were a way to automatically ensure they don't overlap. This may be tricky to do in a backward-compatible way however. Multiple colorbars also overlap by default...

Applies to contourcarpet as well.

Proposal:

  • Always give contour traces the showlegend attribute, and have it default to true for both contours.type='constraint' and contours.coloring='none' traces, false otherwise.
  • Make a way to display even contours with colorscale in the legend.
  • Further discussion needed on if and how to automatically avoid legend/colorbar overlaps

cc @etpinard @phxnsharp

@alexcjohnson alexcjohnson added bug something broken feature something new status: discussion needed labels Aug 7, 2018
@etpinard
Copy link
Contributor

etpinard commented Aug 7, 2018

Always give contour traces the showlegend attribute, and have it default to true for both contours.type='constraint' and contours.coloring='none' traces, false otherwise.

I agree, this should be the default behavior. But I think the contours.coloring: 'none' part qualifies as a backward incompatible change even though contours.coloring: 'none' traces never have colorbars. So I'd vote for making showlegend: false by default whenever contours.type !== 'constraint' in v1 and change to a smarter default in v2.

Make a way to display even contours with colorscale in the legend.

That would be cool. Would contours.showlegend: true | false be too confusing or legendmode: 'trace' | 'contours' be better?

We don't have a clean API for toggling contour levels, so I suspect click/double-clicking on those legend items wouldn't do anything in this iteration?

The legend entry could either just show the line (which has a single color),

Not if contours.coloring is set to 'lines'.

or perhaps for consistency we fill below either using the middle color or with a gradient showing the whole colorscale.

This one is tricky, if we want to cover all cases in one glyph, we could show a gradient corresponding to the colorscale in a rectangle and have its border follow the trace line style.That way contours.coloring: 'line' traces would have unfilled rectangles as legend items,

@phxnsharp
Copy link

@alexcjohnson Yes, looks like my coder created a colorscale that is uniform, not knowing you could do anything else. Here is the typescript that creates the trace:

      return contourDataGenerator.run(zVar.metadata.name, cancelToken)
         .then((results: IContourData) => {

            let trace: IPlotlyContourTrace = {
               colorbar: {
                  exponentformat: PlotlyStdValues.STD_EXPONENT_FORMAT,
                  tickformat: PlotlyStdValues.STD_NUMBER_PRECISION,
                  title: GuiTextService.toNameAndUnitsFromVar(zVar),
               },
               type: 'contour',
               x: results.x1Vals,
               y: results.x2Vals,
               z: results.zVals,
               name: 'Contour: ' + GuiTextService.shortenFullVarNames(zVar.metadata.name),
               hoverinfo: 'none',
               contours: {
                  type: 'levels',
                  coloring: 'lines',
                  showlabels: true,
                  labelformat: PlotlyStdValues.STD_NUMBER_PRECISION,
               },
               colorscale: [[0, color], [1, color]],
            };

            return trace;
         });

And to write it down for posterity, for our use case we do not require the colorscale mode combined with constraints at all. If it is available, we will make it available to our users but our defaults will always draw with contours.coloring set to 'none'.

@alexcjohnson
Copy link
Collaborator Author

Further discussion needed on if and how to automatically avoid legend/colorbar overlaps

Moved this to #420 as it would be a breaking change. The rest of this issue is handled in #2891 so closing.

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

No branches or pull requests

3 participants