Reputation: 4088
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
Upvotes: 7
Views: 5978
Reputation: 1113
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.. :)
Upvotes: 7