I have two data sets:

xy = {{x1, y1}, {x2, y2}, ...}
z = {z1, z2, ...}

I want to plot at each (xi, yi) a point in a two dimensional plane, but color coded according to the value of zi. Next to the plot I want a BarLegend with blue corresponding to the smallest z value and red corresponding to the largest z value.

I already have some code, but I think the Legend is still missing. Of course other more simpler solutions are also welcome.

 colorf = Blend[{{Min[z], Blue}, {Max[z], Red}}, #] &
 pl = 
   Graphics[MapThread[{colorf[#1], Point[#2]} &, {z, xy}], 
     Axes -> True, AspectRatio -> 1, 
     AxesLabel -> {OverTilde["x"], OverTilde["y"]}]
  • $\begingroup$ If you can tell me how to introduce a title in the legend then I agree! $\endgroup$ – Jan SE Dec 19 '17 at 19:01
xy = RandomVariate[NormalDistribution[], {5000, 2}];
z = RandomReal[1, 5000];
colorf = Blend[{{Min[z], Blue}, {Max[z], Red}}, #] &;

pl = Graphics[MapThread[{colorf@#, Point@#2} &, {z, xy}], AspectRatio -> 1, Axes -> True];
barlegend = BarLegend[{colorf, Through[{Min, Max}@z]}, 10, 
   LegendMarkerSize -> 300, LegendLabel -> Style["legend", 16, "Panel"]];

Legended[pl, barlegend]

enter image description here


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