1
$\begingroup$

I want to colour the points in a ListPlot with a list of colours, i.e. something like

data = Table[Cos[x]^2, {x, 0, 10, 0.1}];
colourData = Table[Cos[x]^2, {x, 0, 10, 0.1}];
colours = (ColorData["TemperatureMap"][#] &) /@ colourData;
ListPlot[data,Joined->True (* Something like PlotStyle -> colours*)]

And I want an output that looks like this

enter image description here

$\endgroup$
  • $\begingroup$ Your data can be generated as data = Cos[Range[0, 10, 0.1]] $\endgroup$ – OkkesDulgerci Sep 19 at 14:58
0
$\begingroup$

Ok, I think I have something...

data = Table[Cos[x]^2, {x, 0, 10, 0.1}];
colourData = Table[Cos[x]^2, {x, 0, 10, 0.1}];
colours = (ColorData["TemperatureMap"][#] &) /@ colourData;
ListPlot[data, ColorFunction -> (Blend[colours, #] &), Joined -> True]

enter image description here

This can be used when the data and colourData are different

data = Table[Cos[x], {x, 0, 10, 0.1}];
colourData = Table[Cos[x]^2, {x, 0, 10, 0.1}];
colours = (ColorData["TemperatureMap"][#] &) /@ colourData;
ListPlot[data, ColorFunction -> (Blend[colours, #] &), Joined -> True] 

enter image description here

$\endgroup$
0
$\begingroup$

This question is well covered in ListPlot's documentation on ColorFunction.

data = Table[Cos[x]^2, {x, 0, 10, 0.1}];
ListPlot[data, Joined -> True, ColorFunction -> "TemperatureMap"]

gets you

enter image description here

$\endgroup$
  • $\begingroup$ Thanks but this doesn't answer the question. This method only allows us to use the y values as data for the colour function. Not an arbitrary function, or an arbitrary list of colours. $\endgroup$ – Tom Sep 20 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.