question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set colorscale in template for some trace types

See original GitHub issue

In working on developing templates for plotly.py I’ve found that I’m not able to set the colorscale and colorbar properties in the template for some trace types.

This works as I expect for the heatmap trace type. The defualt colorscale of Viridis and the colorbar tick properties are both applied. Pen: https://codepen.io/jonmmease/pen/mzMeMW

var trace1 = {
  type: 'heatmap',
  z: [[1, 2, 3], [4, 5, 6]],
};

var data = [ trace1 ];

var layout = {
  template: {
    data: {
      heatmap: [{
        colorscale: 'Viridis',
        colorbar: {
          ticks: 'inside',
          ticklen: 10,
          tickcolor: 'white'
        }
      }],
    }
  }
};

Plotly.newPlot('myDiv', data, layout);

newplot-1

But it does not work for the scatter.marker colorscale and colorbar. Pen: https://codepen.io/jonmmease/pen/LgjpQG

var trace1 = {
  type: 'scatter',
  y: [1, 2, 3],
  marker: {
    size: 20,
    color: [1, 2, 3],
    showscale: true
  },
  mode: 'markers'
};

var data = [ trace1 ];

var layout = {
  template: {
    data: {
      scatter: [{
        marker: {
          symbol: 'square',
          colorscale: 'Viridis',
          colorbar: {
            ticks: 'inside',
            ticklen: 10,
            tickcolor: 'white'
          } 
        }
      }],
    }
  }
};

Plotly.newPlot('myDiv', data, layout);

Note that scatter.marker.symbol is being picked up from the template, so I’m pretty sure the template specification is correct, but let me know if I’m missing something.

I’ve noticed this same behavior for other colorscales and colorbars, and I can work through an exhaustive list later today if that’s helpful. Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jonmmeasecommented, Oct 13, 2018

One more issue here. Setting marker.autocolorscale: false in the template causes the colorscale to be displayed properly if the template is already in place when the scatter trace is created. But if the template is applied with relayout after the scatter trace is added, the template’s colorscale is not applied.

0reactions
etpinardcommented, Oct 29, 2018

Would react handle this case better, or would the same issues arise? I

No unfortunately. Only newPlot will behave correctly on layout.template edits.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Colors mode doesn't work with a second added trace - Plotly R
In colScale(as.character(color[[i]])) : Some values were outside the color scale and will be treated as NA. if I comment the lines with the ......
Read more >
add trace in Plotly won't plot the right colour - Stack Overflow
Those traces are inheriting the colorscale you defined. To avoid this you need to specify type = "scatter", mode = "lines", inherit =...
Read more >
Use data bars, color scales, and icon sets to highlight data
On the Home tab, click Conditional Formatting. Conditional Formatting. Point to Color Scales, and then click the color scale format that you want....
Read more >
Visualization with Plotly.Express: Comprehensive guide
Express offers shorthand syntax to create many chart types. ... Plotly comes with several build-in templates including plotly_white, ...
Read more >
Create Custom Color Palettes - Tableau Help
For example, you can create a custom categorical palette that matches your ... to create several custom palettes with 20 or fewer colors...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found