# Plot a table of lists

I want to make a point plot of a table with lists in it. Assume I have data like this:

data={{1,2,3,4},{5,6},{1,5},{2,4}};


and now I want to make a point plot which has points at the following places in the plot: (1,1), (1,2), (1,3), (1,4), (2,5), (2,6), (3,1), (3,5), (4,2) and (4,4).

Is there a quick way to do this, I couldn't figure it out. Thanks in advance!

• try data = {{1, 2, 3, 4}, {5, 6}, {1, 5}, {2, 4}}; points = Flatten[MapIndexed[Transpose@{ConstantArray[First@#2, Length@#], #} &,data], 1]; ListPlot[points, PlotStyle -> Directive[Red,PointSize[Large]]] – Harry Feb 18 '15 at 14:53
• its an ambiguous example. What would you expect if the first list was other than {1,2,3,4} ( == Range[Length@data] ) ? – george2079 Feb 18 '15 at 15:13

I will abuse the fact you want to plot points in specific positions, not get those coordinates:

If you know how to transpose ragged array it is quite strightforward:

ListPlot[Flatten[data, {2}], PlotStyle -> Blue] as pointed out in comments, it is not general so here's something useful:

data = {{1, 2, 3, 4}, {5, 6}, {}, {1, 5}, {2, 4, 7}}; • how...how can this work~~I don't understand~~Flatten[data, {2}]gives {{1, 5, 1, 2}, {2, 6, 5, 4}, {3}, {4}}. how ListPlot handle such ragged list? – Harry Feb 18 '15 at 15:06
• @Harry ListPlot by default puts values on x: 1,2... . And it will do this for every sublist in transposed array: {{1, 5, 1, 2}, {2, 6, 5, 4}, {3}, {4}}. If you remove PlotStyle you can see those sublists. – Kuba Feb 18 '15 at 15:08
• The only problem may appear if you receive list which matches: {{a,b}, {c,d}, ...}, then it may get this wrong and take explicit coordinates from those pairs. – Kuba Feb 18 '15 at 15:09
• I have another question, this doesnt work if my data list contains empty lists, for example data={{1,2},{},{3,4}}, it just skips these. Is it possible to include this? – matti0006 Feb 18 '15 at 15:14
• will it work if the length of lists in the table increase? such as data={{1,2,3,4},{5,6},{1,5},{2,4,7}} ? – Harry Feb 18 '15 at 15:17

another approach:

data= {{1, 2, 3, 4}, {5, 6}, {1, 5}, {2, 4}}
ListPlot[Flatten[
MapIndexed[
Sequence@{#2[], #1} & ,data, {2} ], 1], PlotRange -> {{0, 5}, {0, 8}}] more general example:

 data = {{2, 7, 8, 10}, {5}, {}, {0, 10}, {1, 7},
{4, 9}, {0, 2, 4, 7}, {1}, {2}, {1, 8}} Another way to use MapIndexed:

data2 = MapIndexed[Thread@{First@#2, #1} &, data];
ListPlot[data2, PlotStyle -> PointSize[Large], PlotRange -> {{0, 5}, Automatic}] 