Let’s define a colorbar
Clear["Global`*"]; 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 -> {{"C", None}, {None, None}}, FrameStyle -> Thick, RotateLabel -> False, LabelStyle -> Directive[FontFamily -> "Helvetica", 20], FrameTicks -> {{None, ticks[min, max]}, {None, None}}, FrameTicksStyle -> Directive[FontFamily -> "Helvetica", 20, Plain], ColorFunction -> colorFunction];
where
ticks[min_, max_] := Module[{positions = Range[min, max, (max - min)/5], precision = Length[NestWhileList[10 # &, max/5, Floor@# != # &]] - 1,labels}, If[precision > 0, labels = ToString /@ (NumberForm[#, {Infinity, precision}] & /@ positions)]; If[precision == 0, labels = ToString /@ Floor[positions]]; Transpose[{positions, labels}]] valrange = {0.134512, 10.623245}; Show[colorbar[valrange, "Rainbow"]]
I want the following:
How can we modify the module ticks
, so as to be able to control the number of decimal digits? For example the limits in valrange
have 6 decimal digits, however we may want only 2.
Any suggestions?