5
$\begingroup$

Apologies if the question is too basic; I've searched the manual and the web but couldn't find a solution.

I would like to present some data on a discrete plot. The data is divided into $K$ series or numbers, $y_{k,1}, y_{k,2},\dots, y_{k,r_k}$ (with length $r_k$ depending on $k$, but is small). I would like to plot points corresponding to numbers in one series on a vertical line corresponding to the series. So, on the line ${x=1}$, one unit left of the $y$-axis, I would like to place all the points $y_{1,1}, y_{1,2},\dots, y_{1,r_1}$; then on the line ${x=2}$ I would like to place all the points $y_{2,1}, y_{2,2},\dots, y_{1,r_2}$; and so on. Thus, the points I need on the plot have coordinates $(i,y_{k,i})$. I'm fairly sure Mathematica has something like this as a built in type of plot, but I can't find it. Any help will be appreciated.

$\endgroup$
11
$\begingroup$

Build a sample list

b = Table[RandomReal[{0, 1}, k], {k, 8}]

Plot it:

ListPlot@MapIndexed[Function[{elem, idx}, {idx[[1]], #} & /@ elem], b]

Mathematica graphics

Edit

Also

ListPlot@MapIndexed[Function[{elem, idx}, {idx[[1]], elem}], b, {2}]

And this is another way, without using MapIndexed[]

ListPlot@MapThread[Thread[{#2, #1}] &, {b, Range@Length@b}]
|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you! That's exactly what I needed. $\endgroup$ – Jakub Konieczny Nov 2 '13 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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