9
$\begingroup$
BarLegend[{{Blue, White, Red}, {0, 4}}, 
 Ticks -> {{0, "0"}, {2, "1e-2"}, {4, "2e-2"}}, 
 LegendLayout -> "Column", Charting`TickSide -> Right]

enter image description here

How can I add different ticks on the left side to get something like this

enter image description here

$\endgroup$

1 Answer 1

7
$\begingroup$

We can process the box expressions to add the desired ticks on the left frame:

ClearAll[addLeftFrameTicks]
addLeftFrameTicks[ticks_] := RawBoxes @ Replace[ToBoxes @ #, 
  GraphicsBox[{___, _RasterBox, ___}, ___] -> ToBoxes @ 
   Show[First @ Cases[ToBoxes @ #, 
       g : GraphicsBox[{___, _RasterBox, ___}, ___] :> ToExpression[g], All] & /@ 
    {#, # /. r__Rule :> {Ticks -> ticks, Charting`TickSide -> Left, r}}], All] &;

Examples:

leftticks = {{1, "one"}, {2, "two"}, {3, "three"}};

addLeftFrameTicks[leftticks] @
 BarLegend[{{Blue, White, Red}, {0, 4}}, 
  LegendLabel -> Style["legend", 20], 
  Ticks -> {{0, "0"}, {2, "1e-2"}, {4, "2e-2"}}, 
  LabelStyle -> 14, 
  LegendFunction -> Panel]

enter image description here

Add the options LegendLayout -> "Row" and LegendMarkerSize -> {400, 100} to BarLegend[...] to get

enter image description here

$\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.