Gab*_*iel 5 plot wolfram-mathematica
所以我有一个值矩阵,行对应于数据集,我想使用ListPlot绘制每一个,但我希望有一个不同于索引的x轴.在matlab中我会:
x = 0:4;
ys = [10 20 40 80 160;
20 40 80 160 320;
30 60 120 240 480]';
plot(x,ys)
Run Code Online (Sandbox Code Playgroud)
这将给出三行x值为0-4,y值为每列.
我在Mathematica中最接近的是
x = Range[0,4];
ys = {{10, 20, 40, 80, 160},
{20, 40, 80, 160, 320},
{30, 60, 120, 240, 480}};
ListPlot[Transpose[{x,#}]& /@ ys]
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?这看起来有点神秘.希望有一个我缺少的功能或选项.
在您的特定情况下,由于点是等距的,您可以使用
ListPlot[ys, DataRange -> x[[{1,-1}]]]
Run Code Online (Sandbox Code Playgroud)
希望这不那么神秘.您当然也可以直接使用范围值:
ListPlot[ys, DataRange -> {0, 4}]
Run Code Online (Sandbox Code Playgroud)