在Mathematica中使用两个数据集的ListPlot

Sco*_*ott 3 plot wolfram-mathematica

假设我有理由保持数据集独立,是否有更简洁的方法来执行以下操作?:

x = {1, 2, 3};
y = {1, 4, 9};

ListPlot[Partition[Riffle[x, y], 2]]
Run Code Online (Sandbox Code Playgroud)

谢谢!

rag*_*eld 13

ListPlot [Transpose [{x,y}]]

  • 如果使用Transpose短符号,它甚至更清晰:{x,y} ESC tr ESC (2认同)

Dav*_*rak 13

我不认为Timo的解决方案是标准的.这里有两种方法,使用Transpose或者Thread,我经常看到使用的方法.

x = {1, 2, 3};
y = {1, 4, 9};
Transpose[{x, y}]
Thread[{x, y}]
Run Code Online (Sandbox Code Playgroud)

输出:

{{1, 1}, {2, 4}, {3, 9}}
{{1, 1}, {2, 4}, {3, 9}}
Run Code Online (Sandbox Code Playgroud)

这两种方法都避免明确引用数据的长度,这在我的书中是加号.