7
$\begingroup$

I created a plot with a horizontal BarLegend for TemperatureColors (see1).

Code:

PlotLegends -> 
     Placed[BarLegend[{"TemperatureMap", {15, 30}},Ticks -> Table[i, {i, 15, 31, 1}], LegendMarkerSize -> 300, 
       LegendLabel -> "T(\[Degree]C)", 
       LabelStyle -> {Bold, Black, 11}], {Bottom, Center}] 

Now I just want to have the BarLegend having the temperatures on it decreasing from left to right, means values and colors reversed with high temperatures on the left.

enter image description here

$\endgroup$
8
$\begingroup$
Plot[Sin[x], {x, 0, 1}, 
 PlotLegends -> 
  Placed[BarLegend[{ColorData["TemperatureMap"][1 - #] &, {15, 30}}, 
    LegendMarkerSize -> 300, LegendLabel -> "T(\[Degree]C)", 
    Ticks -> Table[{i, 45 - i}, {i, 15, 31}], 
    LabelStyle -> {Bold, Black, 11}], {Top, Center}]]

Mathematica graphics

$\endgroup$
6
  • $\begingroup$ You do realize that's not supposed to work, right? $\endgroup$
    – rcollyer
    Nov 5 '13 at 14:55
  • 1
    $\begingroup$ @rcollyer Let's write a complain to WRI! :D $\endgroup$ Nov 5 '13 at 14:57
  • 1
    $\begingroup$ You can also use ColorData[{"TemperatureMap","Reverse"}] $\endgroup$ Nov 5 '13 at 16:54
  • $\begingroup$ @SimonWoods Thanks! Never used it $\endgroup$ Nov 5 '13 at 16:59
  • $\begingroup$ @rcollyer why is that not supposed to work? $\endgroup$
    – Chip Hurst
    Nov 5 '13 at 18:41
3
$\begingroup$

LegendLayout -> "ReversedRow"

Using LegendLayout -> "ReversedRow", you can reverse both the color scheme and the ticks without having to touch the color scheme or the ticks list. We need to add padding so that the tick labels are visible:

bl = BarLegend[{"TemperatureMap", {15, 30}}, 
 LegendLabel -> Style["T(°C)", Bold, 11], 
 LegendMarkerSize -> 300,
 "Ticks" -> Range[15, 31], 
 LegendLayout -> "ReversedRow", 
 Method -> {ImagePadding -> {{0, 0}, {20, 0}}}]

enter image description here

Use "TickSide" -> Left and ImagePadding -> {{0, 0}, {0, 20}} to get

enter image description here

Add the option "TickLengths" -> -4 to put the ticks outside the frame:

enter image description here

Use as legend in a Plot object:

Legended[Plot[Sin[x], {x, -2 Pi, 2 Pi}], Placed[bl, Top]] (* 0r *)
Plot[Sin[x], {x, -2 Pi, 2 Pi}, PlotLegends -> Placed[Pane @ bl, Top]]

enter image description here

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