0
$\begingroup$

I have a matrix with 'n' rows and 3 columns where the first two columns are the X and Y values and the third column is f(x,y). All values are numeric. I want to do a 2D-plot where third column gives the colour of the points. How to do it? I want only points and want to plot it like a Temperature map.

$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Commented Jul 10, 2021 at 21:54

2 Answers 2

1
$\begingroup$

With a few bells and whistles

Clear["Global`*"]

SeedRandom[1];
f[{x_, y_}] := {x, y} . {1, 1}^2
data = Append[#, f[#]] & /@ RandomReal[1, {10, 2}];

{zmin, zmax} = MinMax[data[[All, 3]]]

(* {0.3071, 1.80233} *)

Legended[
 Graphics[{
   PointSize[Large],
   {ColorData["TemperatureMap"][
       Rescale[#[[3]], {zmin, zmax}]],
      Tooltip[Point[Most@#], #]} & /@ data},
  Frame -> True,
  Background -> Black,
  FrameStyle -> White,
  FrameLabel -> (Style[#, 14, Bold] & /@ {x, y}),
  PlotRangePadding -> Scaled[.05],
  ImageMargins -> 20],
 BarLegend[{"TemperatureMap", {zmin, zmax}},
  LegendLabel -> Style[z, 14, Bold]]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks! This helps a lot. $\endgroup$
    – SR_00
    Commented Jul 8, 2021 at 14:47
2
$\begingroup$
(** some fake data - a matrix of:
 {{x1,y1,f[x1,y1]},
  {x2,y2,f[x2,y2]},
  ...,
  {xn,yn,f[xn,yn]}} **)

SeedRandom[1];
f[{x_, y_}] := {x, y} . {1, 1}^2
data = Append[#, f[#]] & /@ RandomReal[1, {10, 2}];

(* get a TemperatureMap and scale f[x,y] into [0,1] *)
cf = ColorData["TemperatureMap"];
colsScaled = cf /@ Rescale[data[[All, 3]]];

Graphics[{PointSize[Large],
  Point[data[[All, ;; 2]], VertexColors -> colsScaled]
  }, Axes -> True, Background -> Black, AxesStyle -> White
 ]

temperature color map points plot

$\endgroup$
2
  • $\begingroup$ Black background is because TemperatureMap doesn't show up so well on white - feel free to experiment. $\endgroup$
    – flinty
    Commented Jul 7, 2021 at 13:31
  • $\begingroup$ This Works, Thanks! I forgot the Graphics command. $\endgroup$
    – SR_00
    Commented Jul 7, 2021 at 15:58

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.