5

I have a SwatchLegend with a color scheme:

SwatchLegend[10, {"a", "b", "c", "d", "e", "f", "g"}, 
 LegendLayout -> {"Row", 1}, 
 LabelStyle -> {FontSize -> 16, Bold, Black, FontFamily -> "Arial"}, 
 LegendMarkerSize -> 16]

How can I reverse the colors in the color scheme?

holistic
  • 2,975
  • 15
  • 37

3 Answers3

6

The trick is to go to ColorData. That 10 means ColorData[10], so you can do this:

With[{divs = {"a", "b", "c", "d", "e", "f", "g"}}, 
 SwatchLegend[
  ColorData[10][Length[divs] - # + 1] & /@ Range@Length[divs],
  divs, 
  LegendLayout -> {"Row", 1}, 
  LabelStyle -> {FontSize -> 16, Bold, Black, FontFamily -> "Arial"}, 
  LegendMarkerSize -> 16]
 ]
b3m2a1
  • 46,870
  • 3
  • 92
  • 239
  • Thank you! I did not know I can access the color data like that :). – holistic Aug 03 '17 at 18:42
  • 1
    An alternative is to have Range[] generate the indices in reverse: With[{divs = {"a", "b", "c", "d", "e", "f", "g"}}, SwatchLegend[ColorData[10] /@ Range[Length[divs], 1, -1], divs, LegendLayout -> {"Row", 1}, LabelStyle -> {FontSize -> 16, Bold, Black, FontFamily -> "Arial"}, LegendMarkerSize -> 16]] – J. M.'s missing motivation Nov 06 '17 at 13:54
5

You don't have to reverse colors in color scheme.

Instead, you can simply Reverse your label list and use "ReversedRow" layout:

SwatchLegend[10, Reverse@{"a", "b", "c", "d", "e", "f", "g"}, 
 LegendLayout -> {"ReversedRow", 1}, 
 LabelStyle -> {FontSize -> 20, Bold, Black, FontFamily -> "Arial"}, 
 LegendMarkerSize -> 30]

enter image description here

Similarly, for PointLegend and LineLegend:

PointLegend[10, Reverse@{"a", "b", "c", "d", "e", "f", "g"}, 
 LegendLayout -> {"ReversedRow", 1}, 
 LabelStyle -> {FontSize -> 20, Bold, Black, FontFamily -> "Arial"}, 
 LegendMarkers -> {"\[FilledCircle]", 30}]

enter image description here

LineLegend[10, Reverse@{"a", "b", "c", "d", "e", "f", "g"}, 
 LegendLayout -> {"ReversedRow", 1}, 
 LabelStyle -> {FontSize -> 20, Bold, Black, FontFamily -> "Arial"}, 
 LegendMarkerSize -> 50]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
2
data = {"a", "b", "c", "d", "e", "f", "g"};

SwatchLegend[
 ColorData[10, "ColorList"][[Length@data ;; 1 ;; -1]], data,
 LegendLayout -> {"Row", 1},
 LabelStyle -> {FontSize -> 16, Bold, Black, FontFamily -> "Arial"},
 LegendMarkerSize -> 16]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168