Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Plotly.js default colors list?

I am plotting a plotly bubble chart on a webpage.. I want to get the list of default colors, plotly uses to draw the bubbles.

like image 983
Sushil Kumar Avatar asked Nov 18 '16 09:11

Sushil Kumar


People also ask

What is the default color of Plotly?

The default blue color is "#636EFA".

How do you choose colors in Plotly?

By default, Plotly Express will use the color sequence from the active template's layout. colorway attribute, and the default active template is plotly which uses the plotly color sequence. You can choose any of the following built-in qualitative color sequences from the px. colors.

Does Plotly use JavaScript?

New to Plotly? Plotly is a free and open-source graphing library for JavaScript. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

How do I use Plotly in node js?

Keep the plotly JS file on the front end and render there. Just use node to prep your data and send it over. Personally I prep the entire data of Plotly. newPlot('myDiv', data); in node then get client to request for it, so I can control the looks of the plot server side.


2 Answers

According to the source code of Plotly.js (src/components/color/attributes.js), the default color list is

    '#1f77b4',  // muted blue     '#ff7f0e',  // safety orange     '#2ca02c',  // cooked asparagus green     '#d62728',  // brick red     '#9467bd',  // muted purple     '#8c564b',  // chestnut brown     '#e377c2',  // raspberry yogurt pink     '#7f7f7f',  // middle gray     '#bcbd22',  // curry yellow-green     '#17becf'   // blue-teal 

If you have more than 10 series, you will go back to the first color.

like image 200
KDD Avatar answered Sep 21 '22 17:09

KDD


Plotly uses the same colors as in d3's scale.category10() function. After 10 colors the whole color scheme starts again from 0.

The colors codes can be found in KDD's answer. The snippet below gives the d3 colors and takes the Plotly colors dynamically from a plot, i.e. even if the Plotly changes the color codes will be correct.

var d3colors = Plotly.d3.scale.category10();  var color_div = document.getElementById('colors');  var data = [];    for (var i = 0; i < 11; i += 1) {    data.push({  x: [i],  y: [i + 1],  name: i + ": Color: " + d3colors(i),  type: 'bar'    });  }  Plotly.plot('colors', data);    var node;  var textnode;  for (var i = 0; i < 10; i += 1) {    var color = d3colors(i);    node = document.createElement("div");    node.style.color = color;    var text = "D3: " + color;    textnode = document.createTextNode(text);    node.appendChild(textnode);    node.appendChild(document.createElement("br"));    var rgb = Plotly.d3.selectAll('.point').selectAll('path')[i][0].style.fill;    color = Plotly.d3.rgb(rgb).toString()    var text = "Plotly: " + color + " ; " + rgb;    textnode = document.createTextNode(text);    node.appendChild(textnode);    color_div.appendChild(node);   }
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>  <div id="colors"></div>
like image 27
Maximilian Peters Avatar answered Sep 19 '22 17:09

Maximilian Peters