2

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}]
rcollyer
  • 33,976
  • 7
  • 92
  • 191
Brandon
  • 481
  • 2
  • 10

2 Answers2

7

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.

rcollyer
  • 33,976
  • 7
  • 92
  • 191
0

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

enter image description here