3
$\begingroup$

I am trying to adapt this this question to change the ticks on a BarLegend so have a user-defined continuous BarLegend with ticks

This code allows me to define the ticks I want (sort of, how many compartments I choose does affect things)

BarLegend[{{RGBColor[1, 1, 1], RGBColor[0.3, 0.5, 0.9]}, {0, 1}}, 9, 
 LegendLayout -> "Row", Ticks -> Table[i, {i, 0, 1, 0.2}]]

but I need a continuous gradient, which can be achieved by choosing a high number of compartments, but then the tick labels disappear

BarLegend[{{RGBColor[1, 1, 1], RGBColor[0.3, 0.5, 0.9]}, {0, 1}}, 200, 
 LegendLayout -> "Row", Ticks -> Table[i, {i, 0, 1, 0.2}]]

I will not always have just 2 stops in the gradient.

I also tried to convert a LinearGradientImage into a BarLegend, but was not successful

$\endgroup$

1 Answer 1

4
$\begingroup$

Remove the second argument to get a continuous gradient:

BarLegend[{{RGBColor[1, 1, 1], RGBColor[0.3, 0.5, 0.9]}, {0, 1}}, 
 LegendLayout -> "Row", Ticks -> Table[i, {i, 0, 1, 0.2}]]

enter image description here

Update: "convert a LinearGradientImage into a BarLegend"

Show[LinearGradientImage[{White, RGBColor[0.3, 0.5, 0.9]}, {500, 40}], 
 Frame -> True, 
 FrameTicks -> {{None, None}, {Charting`FindTicks[{0, 500}, {0, 1}], None}}, 
 AspectRatio -> Full, LabelStyle -> 16, ImageSize -> 1 -> {1, 1}]

enter image description here

$\endgroup$
2
  • $\begingroup$ I’m confused as to what is the difference between this and OP’s code, can you please clarify this? $\endgroup$ Apr 27, 2020 at 5:22
  • 2
    $\begingroup$ @CATrevillian, just removed the second argument in OP's code. $\endgroup$
    – kglr
    Apr 27, 2020 at 5:35

Your Answer

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

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