6
$\begingroup$

I have several lists that I plot on the same image like this:

lst02 = {{0.6, 0.0844}, {0.7, 0.077}, {0.8, 0.069}, {0.9, 0.058}};
lst022 = {{0.2, 0.779}, {0.25, 0.597}, {0.3, 0.542}, {0.4, 0.419}};
lst023 = {{0.3, 0.76}, {0.4, 0.555}, {0.5, 0.47}, {0.6, 0.369}};

ListPlot[{lst02, lst022, lst023}, PlotMarkers -> Automatic,
 PlotLegends -> 
  Placed[PointLegend[{Style["a=0.20", 12, Italic], 
     Style["a=0.22", 12, Italic], Style["a=0.23", 12, Italic]}, 
    LegendFunction -> "Frame"], Scaled[{0.85, 0.75}]]]

which yields the following plot:

enter image description here

What I now would like to achieve is to force the legend to be shown in the reverse order. That is, a=0.23 - on top, then a=0.22, and a=0.20 at the bottom of the legend. In this case it would go in the same order as the points on the plot: firstdiamonds, then squares then - disks.

I realize that there is the possibility to make a custom legend. That I can and will do, if no better way could be offered.

I just would like to ask you, if you know a simple built-in way to manipulate the order of the items in the legend.

$\endgroup$
10
$\begingroup$

You can use the built-in function "ReversedColumn" as the LegendLayout option setting:

ListPlot[{lst02, lst022, lst023}, PlotMarkers -> Automatic, 
 PlotLegends -> Placed[PointLegend[{Style["a=0.20", 12, Italic], 
     Style["a=0.22", 12, Italic], Style["a=0.23", 12, Italic]}, 
    LegendFunction -> "Frame", LegendLayout -> "ReversedColumn"], 
   Scaled[{0.85, 0.75}]]]

enter image description here

You can also use LegendLayout -> (Grid[Reverse @ #] &) to get the same result.

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