简体   繁体   中英

Change the color of an specific point in plotly

I am trying to change the color of a specific point in a line graph in plotly. I found out that you can change the color of a trace with this code snippet:

var update = {
marker: {
    color: 'orange',
    size: 10
    }
};

Plotly.restyle('myDiv', update);

I also found out that it is possible to change the color of the first Point with:

Plotly.restyle('myDiv', 'marker.color', [['red']]);

But I don't understand how I am able to change the color of a specific point if I only know his x,y coordinates.

Link to a Codepen

For changing color of only a particular point (or a set of specific points), you can add them as individual traces, and setting the mode to markers . With reference to your codepen link:

var X = [1, 3];
var Y = [4, 3];

Plotly.addTraces(graphDiv,{
    x: X,
    y: Y,
    type: 'scatter',
    mode: 'markers',
    marker: {'color': 'black'},
    name: 'marker_trace'
  });

This will paint all the (X,Y) Pairs as black.

Hope it helps.. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM