1
$\begingroup$

I am doing a simple barchart plot:

data = {{3, 3, 1}, {2, 4, 2}, {1, 2, 3}, {3, 4, 1}};

BarChart[data,
 Frame -> True,
 BaseStyle -> {FontSize -> 28, FontFamily -> "Arial", Black},
 BarSpacing -> {0.1, 2},
 PlotRange -> {All, {-4.5, 6}},
 PlotRangePadding -> {{0, 0.5}, 0},
 AspectRatio -> 0.4,
 FrameStyle -> Directive[Black, AbsoluteThickness[3]],
 ChartLegends -> 
  Placed[SwatchLegend[{Style["A", 23], Style["B", 23], 
     Style["C", 23]}, LegendMarkerSize -> 20, 
    LegendFunction -> (Framed[#, Background -> GrayLevel[0.95], 
        FrameStyle -> Directive[Black, Thick]] &), 
    LegendLayout -> "Row"], Below],
 PlotRangeClipping -> False]

However, I do not get the colors in the legend. Any clue is appreciated.

enter image description here

$\endgroup$
2
  • $\begingroup$ In v.13.2, the colours appear just fine. Maybe a kernel issue? Does it persist restarting mathematica and evaluating the above code? $\endgroup$
    – alex
    Commented Apr 6, 2023 at 12:47
  • $\begingroup$ No issues with color while using v12.2.0 on Win7-x64. $\endgroup$
    – Syed
    Commented Apr 6, 2023 at 12:59

1 Answer 1

1
$\begingroup$

Your code runs with no issues on v.13.2.1, so it is either a version or Kernel issue. In case the problem persists on a fresh start of MMA, then perhaps try by having explicit colours used:

data = {{3, 3, 1}, {2, 4, 2}, {1, 2, 3}, {3, 4, 1}};
cols = System`PlotThemeDump`$ThemeDefaultGradient[[;; ;; 2]];
BarChart[data, Frame -> True, 
 BaseStyle -> {FontSize -> 28, FontFamily -> "Arial", Black}, 
 BarSpacing -> {0.1, 2}, PlotRange -> {All, {-4.5, 6}}, 
 PlotRangePadding -> {{0, 0.5}, 0}, AspectRatio -> 0.4, 
 FrameStyle -> Directive[Black, AbsoluteThickness[3]], 
 ChartLegends -> 
  Placed[SwatchLegend[
    cols, {Style["A", 23], Style["B", 23], Style["C", 23]}, 
    LegendMarkerSize -> 20, 
    LegendFunction -> (Framed[#, Background -> GrayLevel[0.95], 
        FrameStyle -> Directive[Black, Thick]] &), 
    LegendLayout -> "Row"], Below], PlotRangeClipping -> False]

enter image description here

$\endgroup$
2
  • $\begingroup$ Works on 13.2.1 also. $\endgroup$
    – anon
    Commented Apr 6, 2023 at 13:57
  • $\begingroup$ this is very annoying now. I restarted the computer. I have all the updates but still I do not have the colors in the legend. I am running version 12.0.0.0. At least I have a workaround by @Alex. $\endgroup$
    – Luigi
    Commented Apr 7, 2023 at 9:50

Your Answer

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

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