2
$\begingroup$

Good Day to you, I am trying to plot points in a ListPlot/ListPointPlot3D with a ColorFunktion representing the distance to a given point (in my case the Mean point of the data). I have tried this, but its not returning a satisfying result.

    data = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
ListPlot[data,
 ColorFunction -> 
  Function[{x, y}, 
   ColorData["Rainbow"][
    EuclideanDistance[{x, y}, {Mean[data[[All, 1]]], 
      Mean[data[[All, 2]]]}]]],
 PlotStyle -> PointSize[Large]
 ]

Current Result

Current Result

What I want

Desired Result

$\endgroup$
4
$\begingroup$

The arguments passed to the colour functions are rescaled to run between 0 and 1 by default. Disable this with

ColorFunctionScaling -> False

The colour function assumes inputs between 0 and 1 by default. Change this to a suitable range:

ColorData[{"Rainbow", {0, 3}}]

Tip: You could have used Mean[data]. Also, did you mean Mean[ data[[All,2]] ] when computing the 2nd coordinate?

$\endgroup$
1
  • $\begingroup$ Thank you for your help works like a charm. $\endgroup$
    – Tino
    Jan 13 '20 at 10:25

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.