Wolfram mathematica Mathematica中的Plotlegend不适用于函数表
我正在尝试使用Mathematica v8中的PlotLegend绘制带有图例的函数列表。作为一个简单的测试来说明我在做什么Wolfram mathematica Mathematica中的Plotlegend不适用于函数表,wolfram-mathematica,plot,Wolfram Mathematica,Plot,我正在尝试使用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,
<<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]
但是,如果我显式地将表放入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]
对于我的实际应用程序,我将在Do循环中列出一系列函数,因此后一个Plot命令并不理想
如有任何建议,将不胜感激
干杯,
Mike将
绘图[测试,…]
替换为绘图[Evaluate@test,…]
问题是Plot接受未计算的第一个参数,并且仅在计算点时计算它。因此,当它确定标签时,它只看到一个参数
test
,而不是一个列表,因此它只输出一个标签<代码>Evaluate@test告诉Mathematica在将其传递到绘图
之前,先对测试进行求值,即使绘图
被定义为未求值的参数。这样,Plot会看到存储在test
中的列表,并知道如何生成多个标签。用Plot替换Plot[test,…]
[Evaluate@test,…]
问题是Plot接受未计算的第一个参数,并且仅在计算点时计算它。因此,当它确定标签时,它只看到一个参数test
,而不是一个列表,因此它只输出一个标签<代码>Evaluate@test
告诉Mathematica在将其传递到绘图
之前,先对测试进行求值,即使绘图
被定义为未求值的参数。这样,Plot会看到存储在test
中的列表,并知道如何生成多个标签。会Plot[Evaluate@test,…]
帮助?谢谢。这就是诀窍。绘图吗[Evaluate@test,…]
帮助?谢谢。这就是诀窍。
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]