5
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ SwatchLegend[ColorData[10][#]&/@Reverse[Range[7]], {"a", "b", "c", "d", "e", "f", "g"}, LegendLayout -> {"Row", 1}, LabelStyle -> {FontSize -> 16, Bold, Black, FontFamily -> "Arial"}, LegendMarkerSize -> 16] $\endgroup$ – N.J.Evans Aug 3 '17 at 18:35
  • $\begingroup$ Thanks N.J.: Nice solution! $\endgroup$ – holistic Aug 3 '17 at 18:41
  • $\begingroup$ Somewhat related: (106152) $\endgroup$ – Mr.Wizard Aug 3 '17 at 21:19
  • $\begingroup$ Another related question. $\endgroup$ – J. M. will be back soon Aug 4 '17 at 5:25
5
$\begingroup$

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]
 ]
$\endgroup$
  • $\begingroup$ Thank you! I did not know I can access the color data like that :). $\endgroup$ – holistic Aug 3 '17 at 18:42
  • $\begingroup$ 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]] $\endgroup$ – J. M. will be back soon Nov 6 '17 at 13:54
5
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ Thanks kglr, did not discover this option yet, good to know :) $\endgroup$ – holistic Aug 3 '17 at 20:28
  • $\begingroup$ @holistic, my pleasure. $\endgroup$ – kglr Aug 3 '17 at 21:42
2
$\begingroup$
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

$\endgroup$
  • $\begingroup$ Thank you eldo! $\endgroup$ – holistic Aug 3 '17 at 20:28

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.