# How to add Barlegend in ListPlot as z axis?

I have data in the form of x={1,3,5,6,2,4,6,4.5,2.5,2.1,5.7}; y={3,6,2,1,8,4,3,9,11,16,9}; z={0.001,0.004,0.012,0.005,0.002,0.003,0.018,0.09,0.007,0.005,0.009};

Data={1, 3, 0.001}, {3, 6, 0.004}, {5, 2, 0.012}, {6, 1, 0.005}, {2, 8, 0.002}, {4, 4, 0.003}, {6, 3, 0.018}, {4.5, 9, 0.09}, {2.5, 11, 0.007}, {2.1, 16, 0.005}, {5.7, 9, 0.009};

I want to plot the 'x' and 'y' axis in ListPlot(Plotstyle->Dot) and want to add the z-axis as a bar legend against each corresponding value of 'XY'.

• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) 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, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. Feb 2, 2022 at 14:08

Data = Sort[{{1, 3, 0.001}, {3, 6, 0.004}, {5, 2, 0.012}, {6, 1,
0.005}, {2, 8, 0.002}, {4, 4, 0.003}, {6, 3, 0.018}, {4.5, 9,
0.009}, {2.5, 11, 0.007}, {2.1, 16, 0.005}, {5.7, 9, 0.009}}];

colorBar[arg_] := Blend[{Red, Green, Blue}, Rescale[arg, {0, 0.012}]];
ListPlot[Most /@ Data, PlotRange -> All,
ColorFunction :>
Function[{x, y},
colorBar[
Data[[Position[Data[[All, 1]],
Nearest[Data[[All, 1]], x][[1]]][[1, 1]], 3]]]],
ColorFunctionScaling -> False,
PlotLegends ->
BarLegend[{{Red, Green, Blue}, {0, 0.012}},
LegendLayout -> "Column", ChartingTickSide -> Right,
LabelStyle -> {FontSize -> 13, Black}, LegendMarkerSize -> 200,
ColorFunctionScaling -> True, LegendLabel -> "Z"], Frame -> True]
`