TransWikia.com

Plotting points of matrix

Mathematica Asked by SRoy_00 on July 15, 2021

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.

2 Answers

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

Correct answer by Bob Hanlon on July 15, 2021

(** 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

Answered by flinty on July 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP