4
$\begingroup$

Version 9 has a new option Legended, which I find appealing since it should allow me to add individual expressions/curves to a legend, but it doesn't seem to be working for expressions in Plot or LogLinearPlot.

For example, I would like to plot $log(x)$ and $x sin(x)$ together but only have $log(x)$ appear in the legend, I try:

LogLinearPlot[{Legended[Log[x], "Log(x)"], x Sin[x]}, {x, 1, 100}]

and the curve for $Log(x)$ just disappears instead of appearing on it's own in the legend. If Legended is not supposed to be used with the "Plot..." family of symbols, then could someone suggest an alternative solution to my problem?

$\endgroup$
  • $\begingroup$ Yes, that does work for this particular example, because the Log[x] appears first. The complete set of expressions I'm using is a larger than this one and I think the ordering is important since I'm using filling between the curves, which needs to get layered in a particular order (I'll check to see if there's a way I can put all of the legended expressions first). What if I need to put expressions that appear later in the list into the Legend but omit earlier ones? Perhaps I should try to edit my question to include the fact that ordering is important? $\endgroup$ – Alex May 6 '14 at 7:23
  • 2
    $\begingroup$ The documentation for Legended states that Legended can be used as a symbolic wrapper for data elements and datasets in functions such as ListPlot and BarChart. So it does appear that it is not intended to work with the Plot* family. $\endgroup$ – Simon Woods May 6 '14 at 9:15
  • $\begingroup$ Ah, ok, thanks Simon. $\endgroup$ – Alex May 6 '14 at 10:33
  • $\begingroup$ @SimonWoods Do you know why LogLinearPlot[{Log[x], x Sin[x], x Cos[x]}, {x, 1, 100}, PlotLegends -> {"Log(x)", None, "x Cos(x)"}] does not work then ? $\endgroup$ – b.gates.you.know.what May 6 '14 at 10:45
  • $\begingroup$ @b.gatessucks, looks like a bug to me. PlotLegends -> LineLegend@{"Log(x)", None, "x Cos(x)"} works though. $\endgroup$ – Simon Woods May 6 '14 at 11:12
7
$\begingroup$

You can do :

LogLinearPlot[{Log[x], x Sin[x], x Cos[x]}, {x, 1, 100}, 
 PlotLegends -> Placed[{"Log(x)", None, "x Cos(x)"}, After]]

enter image description here

$\endgroup$
  • $\begingroup$ Cheers, that works nicely! $\endgroup$ – Alex May 6 '14 at 10:33

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.