8
$\begingroup$

I have a list that looks like this:

list = {{2}, {3}, {5, 2}, {9, 3, 5}};

I want a plot that looks like this:

enter image description here

Is there a simple way to do this?

$\endgroup$
  • $\begingroup$ @Nasser no, that's not what I want--I'd like the numbers grouped together in the list to be plotted right on top of each other, as shown in the picture. $\endgroup$ – naomig Oct 5 '16 at 1:58
  • $\begingroup$ Ok, will think more. $\endgroup$ – Nasser Oct 5 '16 at 1:59
7
$\begingroup$
list = {{2}, {3}, {5, 2}, {9, 3, 5}};
ListPlot@Flatten[#, 1] &@(Tuples /@ MapIndexed[{#2, #1} &, list])

enter image description here

Or in case you want them to have different colors:

ListPlot[#, PlotStyle -> {Blue, Red, Green, Orange}] &@
      (Tuples/@MapIndexed[{#2, #1} &, list])

enter image description here

$\endgroup$
6
$\begingroup$

How about this? At least until a better solution shows up?

list = {{2}, {3}, {5, 2}, {9, 3, 5}};
r = Table[{Red, PointSize[.02], Point[{i, #}] & /@ list[[i]]}, {i,Length[list]}];
Graphics[r, Axes -> True, AspectRatio -> 1, AxesOrigin -> {0, 0}, 
 GridLines -> Automatic, GridLinesStyle -> LightGray]

Mathematica graphics

$\endgroup$
6
$\begingroup$
list = {{2}, {3}, {5, 2}, {9, 3, 5}};

n = 1; list2 = Thread[{n++, #}] & /@ list

(*  {{{1, 2}}, {{2, 3}}, {{3, 5}, {3, 2}}, {{4, 9}, {4, 3}, {4, 5}}}  *)

ListPlot[list2, AxesOrigin -> {0, 0}]

enter image description here

$\endgroup$
4
$\begingroup$

This is similar to BlacKow's answer, in that MapIndexed[] is the key function for adding the abscissas:

ListPlot[MapIndexed[Transpose[PadRight[{#2, #1}, Automatic, #2]] &, list],
         AxesOrigin -> {0, 0}, GridLines -> Automatic]

clusters of different points

If they are meant to be part of just one set of data, add a Flatten[]:

ListPlot[Flatten[MapIndexed[Transpose[PadRight[{#2, #1}, Automatic, #2]] &, list], 1],
         AxesOrigin -> {0, 0}, GridLines -> Automatic]

clusters all together

$\endgroup$
4
$\begingroup$

Another way to use MapIndexed:

ListPlot[MapIndexed[Thread[{#2[[1]], #}] &, list],
 PlotStyle -> PointSize[.03], PlotRange -> Full, Frame -> True, PlotRangePadding -> 1]

or MapThread

ListPlot[MapThread[Thread[{##}] &, {Range@Length@list, list}],
 PlotStyle -> PointSize[.03], PlotRange -> Full, Frame -> True, PlotRangePadding -> 1]

Mathematica graphics

$\endgroup$
1
$\begingroup$

Another method:

list = {{2}, {3}, {5, 2}, {9, 3, 5}};

ListPlot[PadLeft[list, Automatic, ""]\[Transpose]]

enter image description here

Add e.g. PlotStyle -> Blue for uniform styling:

enter image description here

$\endgroup$

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.