0
$\begingroup$

(This question seems so basic that I have a hard time believing it hasn't been asked yet, but I couldn't find it, so here goes.)

Is it possible to skip items in the legend when using the PlotLegends option in Plot[]? For instance:

Plot[{x, x^2}, {x, -1, 1},
 PlotLegends -> {"I want this entry", "But not this one!"}]

PlotLegends with extraneous entry

I could, of course, do something along these lines, but that seems impractical:

p1 = Plot[x, {x, -1, 1},
 PlotLegends -> {"I want this entry"}];
p2 = Plot[x^2, {x, -1, 1}, 
 PlotStyle -> ColorData[97, "ColorList"][[2]]];
Show[p1, p2]

PlotLegends without extraneous entry, poor man's solution.

$\endgroup$
  • 3
    $\begingroup$ use None for the one you want to skip: PlotLegends -> {"I want this entry", None} $\endgroup$ – egwene sedai Apr 30 at 18:15
  • $\begingroup$ @egwenesedai thanks! I'm surprised that this isn't more obvious in the documentation, but maybe I was overlooking things. $\endgroup$ – Julius Apr 30 at 18:16
  • 1
    $\begingroup$ it's in the details section in the documentation reference.wolfram.com/language/ref/PlotLegends.html $\endgroup$ – egwene sedai Apr 30 at 18:37
  • $\begingroup$ @egwenesedai my bad! Thanks for your answer. $\endgroup$ – Julius Apr 30 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.