3
$\begingroup$

I am trying to adjust height of my color bar, but LegendMarkerSize is not doing what it is supposed to do.

Code

minCf = -0.6;
maxCf = -0.1;
BarLegend[{"Rainbow", {minCf, maxCf}}, 9, LegendMarkerSize -> 500,       LegendLayout -> "Row"]
BarLegend[{"Rainbow", {minCf, maxCf}}, 9, LegendMarkerSize -> {500, 35}, LegendLayout -> "Row"]
BarLegend[{"Rainbow", {minCf, maxCf}},    LegendMarkerSize -> {500, 35}, LegendLayout -> "Row"]

The code works fine for the continuous color bar, but does not work for the discrete one. Below is an output I am getting.

output

enter image description here

Is there anything that I am missing?

I am running Mathematica on Debian 8.

$\endgroup$
  • 1
    $\begingroup$ This is a bug.. $\endgroup$ – Coolwater Mar 12 '16 at 8:02
  • $\begingroup$ @Coolwater I thought so too. $\endgroup$ – molkee Mar 12 '16 at 23:23
  • $\begingroup$ @molkee I see the same effect on 10.4 and it's pretty frustrating. Would you please report it to Wolfram Support and see what they have to say about it? At least they may be able to confirm that it is a bug and not our misunderstanding. I'd appreciate it if you could report back here on what they tell you! $\endgroup$ – MarcoB Mar 14 '16 at 6:14
2
$\begingroup$

In Mathematica 10.1 BarLegend is simply not written to allow the form you want.

When converted to box form BarLegend is handed off to one of two internal functions, iColorGradientLegend or iColorBandLegend.

iColorGradientLegend includes this code:

legendmarkersize = 
 Switch[legendmarkersize, _Scaled, 
  Switch[vorient, 
   "Horizontal", {legendmarkersize, 15}, _, {legendmarkersize, 225}], _?NumericQ, 
  Switch[vorient, 
   "Horizontal", {legendmarkersize, 15}, _, {15, legendmarkersize}], _List, 
  Switch[vorient, 
   "Horizontal", ({If[Legending`LegendDump`sizeQ[First[#1]], First[#1], 220], 
       If[Legending`LegendDump`sizeQ[Last[#1]], Last[#1], 15]} &)[
    legendmarkersize], _, ({If[Legending`LegendDump`sizeQ[First[#1]], First[#1], 
        15], If[Legending`LegendDump`sizeQ[Last[#1]], Last[#1], 225]} &)[
    legendmarkersize]], _, Switch[vorient, "Horizontal", {220, 15}, _, {15, 225}]]

iColorBandLegend uses:

Switch[moptLegendMarkerSize,
 _?NumericQ, vsinglemarkersize = Switch[vorient,
   "Horizontal", {moptLegendMarkerSize*Min[cnumber, 9]^(-1), 15},
   _, {15, moptLegendMarkerSize*Min[cnumber, 9]^(-1)}]; 
 cdefaultdividersizeC = {First[vsinglemarkersize], 1}; 
 cdefaultdividersizeR = {1, Last[vsinglemarkersize]};,
 {_?NumericQ | Automatic, _?NumericQ | Automatic}, 
 vsinglemarkersize = Switch[vorient,
   "Horizontal", {First[moptLegendMarkerSize]*Min[cnumber, 9]^(-1);, 15},
   _, {15, Last[moptLegendMarkerSize]*Min[cnumber, 9]^(-1)}]; 
 cdefaultdividersizeC = {First[vsinglemarkersize], 1}; 
 cdefaultdividersizeR = {1, Last[vsinglemarkersize]};,
 _ | Automatic, vsinglemarkersize = Switch[vorient,
   "Horizontal", cdefaultitemsizeR,
   _, cdefaultitemsizeC]]

The pattern that would match {500, 35} in the latter is {_?NumericQ | Automatic, _?NumericQ | Automatic} and in this case the code uses either First[moptLegendMarkerSize] or Last[moptLegendMarkerSize] depending on the legend orientation, but not both.

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