3
$\begingroup$

How do I make the PlotLabels text colour to match the one with which the data is plotted automatically, eg. in this one:

Plot[{Sin[x], Cos[x], Tan[x], Cot[x]}, {x, -2 \[Pi], 2 \[Pi]}, 
   PlotLegends -> "Expressions", Frame -> False, ImageSize -> Large, 
   PlotLabels -> Placed[Automatic, Below], 
   Ticks -> {Range[-2 Pi, 2 Pi, Pi/4], Automatic}]

eg. in the image below the text cos(x) should be in orange, sin(x) in blue etc. enter image description here

$\endgroup$

1 Answer 1

4
$\begingroup$

I am not aware of a simple built-in solution, but you can construct labels yourself using the default color palette.

exprs = {Sin[x], Cos[x], Tan[x], Cot[x]};
labels = MapThread[Style, {exprs, Take[ColorData[97, "ColorList"], Length[exprs]]}];

Plot[exprs, {x, -2 π, 2 π}, Frame -> False, 
 ImageSize -> Large, PlotLabels -> Placed[labels, Below], 
 Ticks -> {Range[-2 Pi, 2 Pi, Pi/4], Automatic}]

Colored labels

$\endgroup$

Your Answer

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

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