# Coloring the points in a ListPlot with the value of another function [duplicate]

I'm a relative beginner in Mathematica, but after reading the forums for a long time, I couldn't understand one thing:

• I want to plot a list h. Let's call it ListPlot[h]
• I also have a second list, of the same size c
• I want to write a color function that plots a given point in h with a color corresponding to the value of c at the same point.

Anyone knows how to do it?

Perhaps it's better to use Graphics where you have full control over all aspects of the plot:

h = RandomReal[10, {10, 2}];
c = ColorData[1, "ColorList"][[1 ;; 10]];
Graphics[{PointSize[Medium], #[], Point[#[]]} & /@ Transpose[{c, h}], Axes -> True] Regarding your comment, you could do something like this:

h = RandomReal[10, 20];
c = RandomReal[10, 20];

(* You have to give each y value a corresponding x value *)
h = MapIndexed[{First@#2, #} &, h];

(* You have to normalize the concentration so it works with the color function. *)
c = Normalize[c];

colorfunc = ColorData["SolarColors"];

Graphics[{PointSize[Medium], colorfunc@#[], Point[#[]]} & /@ Transpose[{c, h}], Axes -> True]


It's the same idea, but we don't assume that the x coordinate of each point is its position in the list. We also don't assume a list of colors, but rather think of that list as a list of concentration levels.

I noticed now that in m_goldberg's answer he sets the AspectRatio to 1/GoldenRatio, this is an excellent idea since it looks good and is the default aspect ratio for plots in MMA. I too recommend that.

• @Edouard, for a large number of points I would suggest using a gradient color scheme, for example: c = ColorData["Rainbow"] /@ (Range/25); Jan 22 '14 at 16:58
• Thanks a lot ! But actually, what I want to do is not to plot one function as a function of the other. I would like h to be a [1xn] list, and simply plot the n values of "h". But then, to have the values of "h" colorcoded according to the values of "c" at the same x-axis value (without actually plotting "c"). Basically, I want to look at the profile of a a physical interface which has some concentration of molecule at every point. And I would like the interface h(x) to be red (for instance) in regions where the concentration c(x) is high ? Thanks again ! Jan 22 '14 at 17:03
• @Edouard I added something I think should meet your needs. Jan 22 '14 at 17:24

I think Pickett is right to use Graphics, but here is how I would implement it, step-by-step.

Make some data

SeedRandom;
h = RandomInteger[42, 12];
c = Table[Hue[i/Length[h]], {i, 0, Length[h] - 1}];


Make the points.

pts = Point /@ Transpose[{Range[Length[h]], h}]


Color the points.

coloredPts = Transpose[{c, pts}];


Make a plot with 'Graphics.

Graphics[{PointSize[Medium], coloredPts},
Axes -> True, AspectRatio -> 1/GoldenRatio]
` 