2
$\begingroup$

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?

$\endgroup$
3
$\begingroup$
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

| improve this answer | |
$\endgroup$

Your Answer

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

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