0
$\begingroup$

Let's create some sample data

Clear["Global`*"];

n = 10^4;
Nmax = 500;
data = Table[{RandomReal[{-1, 1}], RandomReal[{-1, 1}], 
RandomInteger[{0, 500}]}, {i, 1, n}];

and then color them according to the value of the third column

valrange = {0, Nmax};
data[[All, 3]] = Rescale[data[[All, 3]] // N, valrange];
colfunc[x_, cf_] := ColorData[cf][x[[3]]];
g0 = Graphics[{PointSize[0.005], 
Point[#[[1 ;; 2]], VertexColors -> colfunc[#, "Rainbow"]] & /@ 
 data}];

Clear[colorbar]
colorbar[{min_, max_}, colorFunction_: Automatic, divs_: 150] := 
DensityPlot[y, {x, 0, 0.1}, {y, min, max}, AspectRatio -> 10, 
PlotRangePadding -> 0, PlotPoints -> {2, divs}, MaxRecursion -> 0, 
Frame -> True, FrameLabel -> {{"N", None}, {None, None}}, 
FrameStyle -> Thick, RotateLabel -> False, 
LabelStyle -> Directive[FontFamily -> "Helvetica", 20], 
FrameTicks -> {{None, All}, {None, None}}, 
FrameTicksStyle -> Directive[FontFamily -> "Helvetica", 20, Plain], 
ColorFunction -> colorFunction]

lim = 1;
With[{opts = {ImageSize -> {Automatic, 400}}, cf = "Rainbow"}, 
Row[{Show[{g0}, Axes -> False, Frame -> True, 
FrameLabel -> {"x", "y"}, FrameStyle -> Thick, 
RotateLabel -> False, 
LabelStyle -> Directive[FontFamily -> "Helvetica", 20], 
AspectRatio -> 1, PlotRange -> lim, PlotRangeClipping -> True, 
PlotRangePadding -> None, ImagePadding -> {{90, 20}, {60, 10}}, 
opts], Show[colorbar[valrange, ColorData[cf][#] &], 
ImagePadding -> {{30, 60}, {60, 10}}, opts]}]];

which produces the following

enter image description here

My question is the following: How can I change the color function (in both the main plot and the colorbar) so as to use Hue colors? Moreover, is there a way to control which colors correspond to high and low values and which to intermediate values?

Many thanks in advance!

$\endgroup$
  • 1
    $\begingroup$ Not sure what do you mean be structure an appearance but using VertexColors -> Hue[#[[3]]] and ColorFunction -> Hue answers the first question. $\endgroup$ – Kuba Nov 20 '17 at 14:19
  • $\begingroup$ @Kuba I mean is there a way to control which colors correspond to high and low values and which to intermediate? $\endgroup$ – Vaggelis_Z Nov 20 '17 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.