Mathematica中的Plotlegend不适用于函数表

Mic*_*ham 1 plot wolfram-mathematica

我试图在Mathematica v8中使用PlotLegend绘制一个带有图例的函数列表.作为一个简单的测试,说明我正在尝试做什么.

<<PlotLegends`
test = Table[f[x], {f, {Sin, Cos, Tan, Log, Exp}}]
Plot[test, {x, 0, 1}, PlotRange -> Full, Axes -> {True, False}, 
PlotStyle -> Thick, AxesOrigin -> {0, 0}, 
PlotLegend -> {"Sin", "Cos", "Tan", "Log", "Exp"}, 
LegendPosition -> {0, -0.5}, LegendShadow -> None]
Run Code Online (Sandbox Code Playgroud)

作为输出

{Sin[x], Cos[x], Tan[x], Log[x], E^x}
Run Code Online (Sandbox Code Playgroud)

传奇不正确

但是,如果我明确地将表放在Plot命令中,我会得到正确的图例.

Plot[{Sin[x], Cos[x], Tan[x], Log[x], Exp[x]}, {x, 0, 1}, 
PlotRange -> Full, Axes -> {True, False}, PlotStyle -> Thick, 
AxesOrigin -> {0, 0}, 
PlotLegend -> {"Sin", "Cos", "Tan", "Log", "Exp"}, 
LegendPosition -> {0, -0.5}, LegendShadow -> None] 
Run Code Online (Sandbox Code Playgroud)

正确的传说

对于我的实际应用,我将Do循环中的函数列表放在一起,因此后一个Plot命令并不理想.

任何建议将不胜感激.

干杯,迈克

cel*_*chk 6

替换Plot[test, ...]Plot[Evaluate@test, ...].

问题是Plot采用未评估的第一个参数,并且仅在计算点时对其进行评估.因此,当它确定标签时,它只能看到一个参数test,而不是列表,因此它只输出一个标签.Evaluate@test告诉Mathematica test在传递它之前进行评估,Plot即使Plot被定义为将参数取消评估.这样,Plot可以看到您存储的列表test并知道生成多个标签.