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

enter image description here

the expected image is produced.

But, when SetDelayed is used,

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

enter image description here

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.

  • $\begingroup$ I have the same problem - does anyone have a fix? $\endgroup$ – 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.

enter image description here


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.