wolfram-mathematica - 请在 Mathematica 中解释这段创建热/强度图的代码

标签 wolfram-mathematica

Graphics@Flatten[Table[

(*colors, dont mind*)
{ColorData["CMYKColors"][(a[[r, t]] - .000007)/(.0003 - 0.000007)], 

(*point size, dont mind*)
PointSize[1/Sqrt[r]/10], 

(*Coordinates for your points "a" is your data matrix *)
   Point[
        {(rr =Log[.025 + (.58 - .25)/64 r]) Cos@(tt = t 5 Degree), 
          rr Sin@tt}]
        } &@

 (*values for the iteration*)
 , {r, 7, 64}, {t, 1, 72}], 1] 

 (*Rotation, dont mind*)
 /. gg : Graphics[___] :> Rotate[gg, Pi/2]  

最佳答案

好吧,我会咬人的。首先,Mathematica 允许通过 several forms 之一应用函数。 : 标准表格 - f[x] , 前缀形式 - f @ x , 后缀形式 - f // x , 和中缀形式 - x ~ f ~ y . Belisarius 的代码同时使用了标准和前缀形式。

那么,让我们先看看最外层的函数:Graphics @ x /. gg : Graphics[___]:> Rotate[gg,Pi/2] , 其中xFlatten里面的所有东西吗? .本质上,这样做是创建一个 Graphics来自 x 的对象并使用 named pattern ( gg : Graphics[___] ) 旋转结果 Graphics对象 90 度。

现在,创建一个 Graphics对象,我们需要提供一堆原语,这是嵌套列表的形式,其中每个子列表描述一些元素。这是通过 Table 完成的具有以下形式的命令:Table[ expr, iterators ] .迭代器可以有多种形式,但这里它们的形式都是 {var, min, max} ,并且由于它们缺少第 4 项,因此它们取 min 之间的每个值和 max在整数步。所以,我们的迭代器是 {r, 7, 64}{t, 1, 72} , 和 expr对它们所具有的每个值进行评估。因为,我们有两个迭代器,这会产生一个矩阵,这会混淆 Graphics , 所以我们使用 Flatten[ Table[ ... ], 1]我们将矩阵的每个元素放入一个简单的列表中。

Table 的每个元素产生的只是:颜色(ColorData)、点大小(PointSize)和点位置(Point)。所以,用 Flatten ,我们创建了以下内容:

Graphics[{{color, point size, point}, {color, point size, point}, ... }]

颜色生成是从数据中获取的,它假定数据已放入名为 a 的列表中. a 的各个元素通过 Part 访问构造: [[]] .从表面上看,ColorData构造有点奇怪,但可以读作 ColorData["CMYKColors"]返回 ColorDataFunction 当提供 0 到 1 之间的值时,它会产生 CMYK 颜色值。这就是为什么数据来自 a按原样缩放。

点的大小是从径向坐标生成的。你会期待 1/Sqrt[r]磅值应该越来越小,如 r增加,但 Log反转比例。

类似地,点位置由径向和角度 (t) 变量生成,但是 Point只在 {x,y} 中接受它们形式,所以他需要转换它们。在 {r,t} 的转换中出现了两个奇怪的构造至 {x,y} : 两者都是 rrttSet ( = ) 在计算 x 时允许在计算 y 时使用它们.此外,术语 t 5 Degree让 Mathematica 知道角度是度数,而不是弧度。此外,如所写,有一个错误:紧随关闭 } , 条款 &@不应该在那里。

这有帮助吗?

关于wolfram-mathematica - 请在 Mathematica 中解释这段创建热/强度图的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5171164/

相关文章:

wolfram-mathematica - 在新版本的Mathematica中制作版本5的旧版文档的工作副本

wolfram-mathematica - 数学 : Plot the derivative of a piecewise function

wolfram-mathematica - Mathematica中如何自定义多项式的显示顺序

python - 当 Mathematica 轻松成功时,SymPy 的零空间陷入困境

wolfram-mathematica - Mathematica 中的语法着色

wolfram-mathematica - 导出在MMA8中损坏的图形对象行

c - Mathematica 和 C/C++ : Exchanging Data

wolfram-mathematica - 如何告诉 Mathematica 将 0 替换为 1 的幂?

用于出版质量图的 Python Pylab pcolor 选项

wolfram-mathematica - 在 Manipulate 内绘制 NDSolve