matlab like multiline plot in Mathematica
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]
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}]
精彩评论