3
$\begingroup$
j=0;   
ListLinePlot[Table[u[i][j] , {i, 0, Xmax}], PlotRange -> All]

here u is 2 D array and I want to plot all the columns of this 2D matrix in a single graph.

$\endgroup$
1
  • $\begingroup$ First I am specifying particular value of j then plot is coming. I want to make it in loop such that i can have plots at various j's. $\endgroup$ Commented Jul 17, 2018 at 8:47

1 Answer 1

3
$\begingroup$
u = Array[# #2 &, {10, 7}];
u // MatrixForm // TeXForm

$\left( \begin{array}{ccccccc} 1 & 2 & 3 & 4 & 5 & 6 & 7 \\ 2 & 4 & 6 & 8 & 10 & 12 & 14 \\ 3 & 6 & 9 & 12 & 15 & 18 & 21 \\ 4 & 8 & 12 & 16 & 20 & 24 & 28 \\ 5 & 10 & 15 & 20 & 25 & 30 & 35 \\ 6 & 12 & 18 & 24 & 30 & 36 & 42 \\ 7 & 14 & 21 & 28 & 35 & 42 & 49 \\ 8 & 16 & 24 & 32 & 40 & 48 & 56 \\ 9 & 18 & 27 & 36 & 45 & 54 & 63 \\ 10 & 20 & 30 & 40 & 50 & 60 & 70 \\ \end{array} \right)$

To plot all columns simply Transpose the matrix u:

ListLinePlot[Transpose @ u, PlotLegends -> Range[7]]

enter image description here

To plot only a subset of columns, e.g. columns 1, 3, 6, and 7:

ListLinePlot[Transpose[u][[{1, 3, 6, 7}]],  PlotLegends -> {1, 3, 6, 7}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.