I have a data file which has 3 columns (let's call them x, y, p). Here x and y columns represent the co-ordinates in the 2-d plane while the third column p represent the probability of an event happening at the value of (x,y). I want to make a 2-d ListPlot such that the color of a point at (x,y) is decided by the value of p at that point. Since I have 100 such points in my file, the probability p at each points are quite small (as total probability add up to 1). So I need to rescale the colorfunction in a clever way so that I get a smoothly color varying plot. Can someone help me about how to rescale the colorfunction?

  • 1
    $\begingroup$ You can rescale your p list to run on {0, 1} and use this in ColorData: ColorData["TemperatureMap"]/@Rescale[p,MinMax[p],{0,1}]. $\endgroup$
    – Alx
    Commented Sep 29, 2019 at 12:55

1 Answer 1


Like Alx said in a comment, what you have to do is to rescale your data before you pass it to the color function, which you can do with Rescale.

You can use the maximum value in the list as the upper value, and the minimum value in the list as the lower value, but sometimes it is preferable to scale the color function to a certain range so that the color function stays consistent if the data changes. I will show how to do that:

xy = RandomReal[1, {100, 2}];
p = RandomReal[{0, 0.1}, 100];
cf = ColorData["TemperatureMap"]@Rescale[#, {0, 0.1}] &;
colors = cf /@ p;
data = MapThread[Style, {xy, colors}];

 PlotLegends -> Placed[BarLegend[{"TemperatureMap", {0, 0.1}}], Right]

Mathematica graphics

I included a bar legend to show that it has to be scaled separately.

  • 1
    $\begingroup$ One can actually give the range of the color function directly in ColorData: ColorData[{"Rainbow", {-0.2, 0.5}}] $\endgroup$
    – SHuisman
    Commented Sep 30, 2019 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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