Black Lives Matter. Please consider donating to Black Girls Code today.

Want to create line graph with different colours depending on x value

I have a graph which displays signal to noise ration for 4096 channels and I need to split the 4096 channels up into groups so that the line changes colour depending on the group the x value belongs to, so for example the first 800 x values belong to group 1 and are red, the next 1000 are group 2 and are blue and so on. The plot line must be continuous just changing colour on each boundary. Is this possible and if so how?

There’s no easy way to do this unfortunately.

We don’t allow per-segment coloring on line traces. See for more on that topic.

So, what I would do it split your data into multiple traces, one trace per group where each trace has a different line.color setting.

Thanks for the reply. This suggestion has raised another question. I am now defining each range as s separate trace or plot but when it creates the graphs there is a gap between each one. How do I have one continuous plot line rather than the gaps between each individual trace I have specified?

1 Like

I’m having the same issue when I’m trying to color a line plot based on the Y-axis values. I’m adding the segments as four different traces. Although there are no actual gaps in the data, the colored line plot has data gaps when changing from one color to another. Has anyone figured out a solution for this issue?