# Does PlotLegends not work in MM 11?

I literally just downloaded MMA11 and upgraded from MMA 10.4, and PlotLegends seems to not work the way it did previously... Kind of annoying. Anyone knows why?

 Clear[var, expr, blah, g, derivatives];
var = Input["Type a variable, such as x, in this window."];
expr = Input["Type an expression to be differentiated in the variable you just typed in the last window."];
g[blah_] = expr /. {var -> blah};
derivatives := {g[var], g'[var]}
Plot[{derivatives}, {x, -3, 5}, {PlotLegends -> "Expressions",
PlotLabel -> "A function and its Derivative", PlotRange -> 10}]

• Do you have a more minimal example demonstrating this that doesn't reply on Input statements? – ktm Nov 4 '16 at 18:46
• Try changing Plot[{derivatives},...] into Plot[Evaluate@derivatives,...] – corey979 Nov 4 '16 at 18:49
• It works PERFECTLY fine on 10.3.. I have both versions and just ran the same exact code. – Brandon Nov 4 '16 at 18:50
• Your code (without Evaluate) doesn't work for me on v10.4.1. // It's not a bug, it's a normal behaviour. – corey979 Nov 4 '16 at 18:53
• Make sure you upgrade to 11.0.1 if you have 11.0.0. – Szabolcs Nov 4 '16 at 19:21

First of all, this is not a bug in PlotLegends. You can tell because the plot itself is using the color for a single data set, implying that it thinks there is only one multi-valued function present. Since PlotLegends with "Expressions" or Automatic is sensitive to the number of functions, they will not display a legend when only one is present. The issue is then with how Plot is interpreting derivatives.

After a little experimentation, it comes down to the use of SetDelayed vs Set. When Set is used to define the variable,

d1 = {Sin[x], Cos[x]}
Plot[d1, {x, 0, 2 Pi}]


the expected image is produced.

But, when SetDelayed is used,

d2 := {Sin[x], Cos[x]}
Plot[d2, {x, 0, 2 Pi}]


it does not. There was some work on the parser between 10.3 and 10.4 which is likely causing this change in behavior, but I am not inclined to consider this a bug. Simply, with SetDelayed the function is expected to be evaluated over and over again, and should be thought of as the equivalent of using

f[x_] := {Sin[x], Cos[x]}
Plot[f[x], {x, 0, 2 Pi}]


which generates a plot identical to d2.

Correction: after looking at this again, and actually running this with PlotLegends with Set being used shows the same behavior. Therefor, I would say it is a bug.

• I have the same problem - does anyone have a fix? – Howard Lovatt Apr 4 '18 at 23:30

If you add Evaluate to the expression to be plotted there it works. Must be some bug in Plot.