开发者

matlab like multiline plot in Mathematica

开发者 https://www.devze.com 2023-02-19 03:02 出处:网络
So I have a matrix of values were the rows correspond to sets of data, and I want to plot each of these using ListPlot but I want to have a different x-axis than the index. In matlab I would have:

So I have a matrix of values were the rows correspond to sets of data, and I want to plot each of these using ListPlot but I want to have a different x-axis than the index. In matlab I would have:

x = 0:4;

ys = [10 20 40 80 160; 
开发者_JS百科      20 40 80 160 320; 
      30 60 120 240 480]';

plot(x,ys)

and this would give three lines with x-values 0-4 and the y-values being each column.

The closest I could come up with in Mathematica is

x = Range[0,4];

ys = {{10, 20, 40, 80, 160},
      {20, 40, 80, 160, 320},
      {30, 60, 120, 240, 480}};

ListPlot[Transpose[{x,#}]& /@ ys]

matlab like multiline plot in Mathematica

Is this the correct way? It seems a bit cryptic. Hoping there is a function or option I am missing.


In your particular case, since the points are equidistant, you can use

ListPlot[ys, DataRange -> x[[{1,-1}]]]

Hope this is less cryptic. You can of course also use the range values directly:

ListPlot[ys, DataRange -> {0, 4}]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号