Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Change color of a specific point in line graph

Hi,
I am trying to change the color of a point in a line graph. I found out that you can change the first point of the graph via:

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

But how can i change the color of another point ? (let’s say the 5th). Best case would be if i can access the point via his x,y coordinates.

Thank you for your help!

I suggest you read through the discussion in https://github.com/plotly/plotly.js/issues/144

Gecko, did you find a solution? I’m looking to do the same thing but i can’t figure it out from the discussion. What if you want to highlight point x of all points in the plot regardless what trace they belong to?

I’m doing something similar, i pass an array with the colors of every point, i dont try to change at any moment but probably you can change the value of the array at any point and relayout it.

var colorsForThresholds = []; //fill it properly
var symbolForThresholds = [];
var trace = {
x: datesArray,
y: dataForPlot,
errors: [],
type: ‘scatter’,
name: ‘Alarms’,
mode: ‘lines+markers’,
marker: {
color: colorsForThresholds,
symbol: symbolForThresholds,
size: 5
}
};