# How to reverse the order in which ListPlot plots multiple array of numbers?

I am new to mathematica. I have been trying to plot a list of values. The list looks somewhat like this:

list = {{1, 2}, {1, 2, 3}, {1, 2, 3, 4}}


What I want is to plot, $$\{1,2\}$$ (both these points) at $$x =1$$, and points $$\{1,2,3\}$$ at $$x =2$$, etc. I tried converting the list to a form $$\{\{1,1,1\},\{2,2,2\},\{3,3\},\{4\}\}$$ and list plotting, but this puts $$\{1,2\}$$ at $$x = 3$$, rather than $$x = 1$$. So if I can make ListPlot plot first values at $$x = 3$$ and go backwards from there my problem can be solved. But I could not find a way to specify the $$x$$ values for ListPlot.

• Please consider adding the ListPlot you used to your question, so that people can see what you've tried. Nov 28, 2020 at 17:50

One possible approach is to use PadRight to obtain a rectangular 4X3 array :

list = {{1, 2}, {1, 2, 3}, {1, 2, 3, 4}}


{{1, 1, 1}, {2, 2, 2}, {Null, 3, 3}, {Null, Null, 4}}

and then ListPlot :

ListPlot[Transpose[ PadRight[list, Automatic, {Null}]] ]


• I think Missing[] instead of Null would be preferable, even though any non numeric value works here. Nov 29, 2020 at 12:02
list = {{1, 2}, {1, 2, 3}, {1, 2, 3, 4}};


Add x-coordinates to each data point using MapIndexed + Thread:

list2 = MapIndexed[Thread[{#2[[1]], #}] &] @ list

{{{1, 1}, {1, 2}},
{{2, 1}, {2, 2}, {2, 3}},
{{3, 1}, {3, 2}, {3, 3}, {3, 4}}}

ListPlot[list2, PlotStyle -> PointSize[Large], PlotLegends -> InputForm /@ list]


You can also use MapIndexed + Tuples, or MapThread + Thread to construct list2:

list3 = MapIndexed[Tuples @* Reverse @* List] @ list;;

list4 = MapThread[Thread @* List] @ {Range @ Length @ list, list};

list2 == list3 == list4

True


Table is OK.

n = 10;
list = Range[Range[2, n]]
Table[Table[{i, j}, {j, list[[i]]}], {i, 1, Length@list}]
ListPlot[%]


f[{a___, b_}] := {b - 1, #} & /@ {a, b}

f /@ {{1, 2}, {1, 2, 3}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}} // ListPlot