1
$\begingroup$

Suppose I have a data set

data={{0,0,-1},{0,1,-0.5},{1,1,0},{2,1,0.5},{2,2,1}};

where the first two coordinates are x and y values, and the third is input for the color gradient function

crgrad[x_] := Blend[{{-1, Blue},{0, Black}, {1, Red}}, x];

What is the correct way to plot the data points and have each point be its corresponding color? I have already tried

dataPlt = Graphics[{Point[{#1, #2}], ColorFunction -> (crgrad[#3])} & @@@ data];

I also want to incorporate

ColorFunctionScaling -> False

Thanks!

$\endgroup$
2
  • $\begingroup$ Graphics[{crgrad[#3], Point[{#1, #2}]} & @@@ data]? $\endgroup$
    – kglr
    Mar 29, 2016 at 5:10
  • $\begingroup$ Thanks for the reply, but that also does not work. $\endgroup$
    – S2167
    Mar 29, 2016 at 6:04

1 Answer 1

1
$\begingroup$

If you do not have to use ColorFunction, you can use

Graphics[{crgrad[#3], PointSize[.05], Point[{#1, #2}]} & @@@ data]

Mathematica graphics

or

Graphics[{PointSize[.05], Point[{#1, #2}, VertexColors -> crgrad[#3]]} & @@@ data]

Mathematica graphics

or

ListPlot[Style[{#, #2}, crgrad[#3], PointSize[.05]] & @@@ data, 
 Axes -> False, PlotRangePadding -> .2, AspectRatio -> 1]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ For some reason I could not get the method to work after reading your comment, but it now works brilliantly. Thank you. $\endgroup$
    – S2167
    Mar 29, 2016 at 7:07
  • $\begingroup$ @S2167, thank you for the accept. $\endgroup$
    – kglr
    Mar 29, 2016 at 8:31

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.