The function BarLegend[{"Rainbow",{0,1}},4] should result in a bar legend with range 0 to 1 with 4 equally spaced contours.

I was hoping to get contours at {0.2, 0.4, 0.6, 0.8} but found them at {0.19,0.38,0.57,0.76} which are equally spaced but don't properly span the range

How should i go about getting the result i expected?


1 Answer 1

BarLegend[{"Rainbow", {0, 1}}, {Automatic, 5}]

enter image description here

You can also use FindDivisions$[\{x_{min}, x_{max}\}, n]$ to get a list of about n "nice" numbers that divide the interval around $x_{min}$ to $x_{max}$ into equally spaced parts to specify the contours list

BarLegend[{"Rainbow", {0, 1}}, FindDivisions[{0, 1}, 5]]

same picture

You can also use a list of contours in the second argument:

BarLegend[{"Rainbow", {0, 1}}, Subdivide[5]]

same picture


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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