2

I had an odd issue where my plot wasn't drawn correctly when I called it via Plot[Join[fs,gs], (*..*)]. However, these two versions worked:

funcs = Join[fs,gs]; Plot[funcs, (*..*)]           (*1*)

plot[fs_] := Plot[fs,(..)] plot[Join[fs,gs]] (2)

After a bit of playing around and a bit of research, I found out that explicitly Evaluate-ing the Join expression fixes the plot, so

Plot[Evaluate[Join[fs,gs]],(*..*)]                 (*3*)

works the same way as the two other examples. It turns out, Plot has the attribute HoldAll set whereas Set and SetDelayed do not.

Hence I suspect that $(1)$ and $(2)$ evaluate the Join expression before passing it to the plot. But

  1. Is there a reason why Plot holds its arguments?
  2. Does that mean if my expression for the plot gets more intricate, I should always Evaluate just to be sure? The documentation just says

In some cases, it may be more efficient to use Evaluate to evaluate f symbolically before specific numerical values are assigned to x.

xzczd
  • 65,995
  • 9
  • 163
  • 468
Niklas Vest
  • 121
  • 4
  • 7
    I believe it's to allow Plot to localize the independent variable before evaluation so as to avoid any existing definition. – John Doty Feb 05 '22 at 21:39
  • 1
    Related: https://mathematica.stackexchange.com/questions/1731/plot-draws-list-of-curves-in-same-color-when-not-using-evaluate. In particular, Mr. Wizard's answer recommends using Evaluated -> True instead of Evaluate[funcs]. – Michael E2 Feb 06 '22 at 05:58

0 Answers0