Mathematica 帮助中的 ColorFunctionScaling 示例失败 - 为什么?
Mathematica 7 帮助中有一个关于 Plot > 的示例选项> ColorFunctionScaling。
Table[Plot[Sin[4 Pi x], {x, 0, 1/2}, PlotStyle -> Thick,
ColorFunction -> Function[{x, y}, Hue[x]],
ColorFunctionScaling -> cf], {cf, {False, True}}]
当我自己在 Mathematica 7 上对其进行评估时,两个输出图看起来都像一个在左边。
但是,如果我对此进行评估,我会得到右侧的图,如上所示:
Plot[Sin[4 Pi x], {x, 0, 1/2}, PlotStyle -> Thick,
ColorFunction -> Function[{x, y}, Hue[x]],
ColorFunctionScaling -> True]
为什么给出的示例可能会失败?
Alexey 和 Simon 证明这不是 HoldAll 的结果,正如我之前推测的那样。
该示例的存在让我怀疑它曾经有效,并且它在版本 8 上有效的信息告诉我行为已经改变。究竟发生了什么变化?
There is an example in the Mathematica 7 help for Plot > Options > ColorFunctionScaling.
Table[Plot[Sin[4 Pi x], {x, 0, 1/2}, PlotStyle -> Thick,
ColorFunction -> Function[{x, y}, Hue[x]],
ColorFunctionScaling -> cf], {cf, {False, True}}]
When I evaluate it myself on Mathematica 7, both output plots look like the one on the left.
However, if I evaluate this, I get the plot on the right, as shown above:
Plot[Sin[4 Pi x], {x, 0, 1/2}, PlotStyle -> Thick,
ColorFunction -> Function[{x, y}, Hue[x]],
ColorFunctionScaling -> True]
Why might the example as given fail?
Alexey and Simon demonstrated that this is not the result of HoldAll, as I presumed before.
The existence of the example leads me to suspect it once worked, and the information that it works on version 8 tells me that the behavior has changed. What precisely has changed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的问题真的很有趣。所提到的向内置函数提供选项值的方法在文档中广泛使用。事实上,它仅对
ColorFunctionScaling
失败,这看起来像是一个错误。并且在 v.8 中不存在此问题的信息证实了这是 v.7 中的错误。无论如何,请考虑以下事项:
您可以看到
HoldAll
属性确实不会阻止替换cf
。这样一来,v.7 中
Plot
与Table
所描述的错误行为的原因是什么,这真的很有趣?Your question is really interesting. The mentioned method of supplying option values to built-in functions is widely used in the Documentation. The fact that it fails only for
ColorFunctionScaling
looks like a bug. And information that in v.8 this problem does not exist confirms that this is a bug in v.7.In any way consider the following:
You can see that
HoldAll
attribute in really does not prevent substituting ofcf
.In this way, it is really interesting what was the cause of described buggy behavior of
Plot
withTable
in v.7?评估顺序似乎有点不对劲。如果您在查看
Plot
命令之前强制替换cf
,它就会起作用。为此,我们使用With[{x=x},...]
构造:奇怪的是,在 Mathematica 版本 8 中不需要这样的拼凑。
更奇怪的是,Mathematica 7 文档有一个示例,其中预评估的图形与该版本生成的图形不匹配。 (不错的发现,顺便说一句)
The evaluation order seems slightly out. It works if you force
cf
to be substituted in before thePlot
command is looked at. To do this we use theWith[{x=x},...]
construct:It's strange that you don't need such a kludge in Mathematica version 8.
It's even stranger that the Mathematica 7 documentation has an example where the pre-evaluated graphics does not match what is produced by that version. (Nice find, btw)
这个错误实际上与 HoldAll 属性有关,但我被 此自动加载问题 认为事实并非如此。这可以通过执行以下命令看出:
需要第一个
Plot
来激活包加载。因此,可以通过包装 ColorFunctionScaling -> 来获得正确的行为。 ... 在
评估
中:This bug in fact is related to the HoldAll attribute, but I was fooled by this auto-load issue into thinking it was not. This can be seen by executing this:
The first
Plot
is needed to activate the package load.One can therefore get the correct behavior by wrapping
ColorFunctionScaling -> ...
inEvaluate
: