6
$\begingroup$

I was wondering if it possible to change the shape of top and bottom of a barlegend as in this picture

enter image description here

$\endgroup$

2 Answers 2

8
$\begingroup$

This uses code from here to convert BarLegend to Graphics. Then two triangles are added to top and bottom.

grad = "LightTemperatureMap";
minmax = {-1, 1};

leg = ToExpression[MakeBoxes[BarLegend[{grad, minmax}]][[1, 1]]][[1]];
leg /. leg[[1, 2, 
    4]] -> {Line[{#1, (#1 + #2)/2 - {0, 2*#1[[1]]}, #2, #3, (#3 + #4)/
        2 - {0, 2*#3[[1]]}, #4, #1} & @@ leg[[1, 2, 4, 1]]], {Opacity[
     1], EdgeForm[ColorData[grad][0]], ColorData[grad][0], 
    Triangle[{#1, (#1 + #2)/2 - {0, 2*#1[[1]]}, #2} & @@ 
      leg[[1, 2, 4, 1]]], EdgeForm[ColorData[grad][1]], 
    ColorData[grad][1], 
    Triangle[{#3, (#3 + #4)/2 - {0, 2*#3[[1]]}, #4} & @@ 
      leg[[1, 2, 4, 1]]]}}

enter image description here

$\endgroup$
7
$\begingroup$

Sure, but you have to do everything manually. There is a related post here. I will use this solution as a starting point and add a RegionFunction

plotoptions = {ColorFunction -> (ColorData["Rainbow"][
       Rescale[#, {0, .125}]] &), 
   MeshFunctions -> 
    Table[#3 &, {i, 1, Length[{0, .025, .05, .075, .1, .125}]}], 
   Mesh -> Table[{{tick, 
       Lighter[White, 
        HeavisideTheta[(tick/
            Max[{0, .025, .05, .075, .1, .125}]) - .5]]}}, {tick, {0, \
.025, .05, .075, .1, .125}[[2 ;; -2]]}], 
   MeshStyle -> {Dotted, DotDashed, Dashed, AbsoluteThickness[.5]}};

Table[ContourPlot[y, {x, 0, 1}, {y, 0, .125}, 
   RegionFunction -> 
    Function[{x, y, z}, Abs[16 (y - .125/2)] + w Abs[x - 1/2] <= 1], 
   Contours -> 100, ContourLines -> False, PlotRange -> All, 
   ColorFunctionScaling -> False,(*Frame\[Rule]{{False,True},{False,
   False}},*)FrameStyle -> 
    Directive[RGBColor[.8, .8, .8], FontColor -> Black], 
   FrameTicks -> {{None, {0, .025, .05, .075, .1, .125}}, {None, None}},
    AspectRatio -> 5, ImageSize -> 100, 
   Evaluate@plotoptions], {w, {1, 0.5, 0.3, 0.1}}]

pointy BarLegends

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.