# Plotting many tables in a single plot

I have several lists.

HeapSort = {6046.315617631054, 10120.421973039713, 20443.896966227818, 39888.26738991704, 409953.65081967216, 822796.7730263158, 1668210.1566666667, 3417061.523809524, 7231431.842857143, 1.58387906875*10^7, 3.3356646333333332*10^7, 6.99283795*10^7};
InsertSort = {1271.5641210832696, 2687.027971840069, 7428.082168377579, 26163.114593689497, 3480848.111111111, 1.7492152862068966*10^7, 7.876655514285715*10^7, 4.397160115*10^8, 2.19177605*10^9, 9.608922293*10^9, 4.5711371557*10^10,  2.88336011071*10^11};
MergeSort = {705.8025660136586, 757.6872519529326, 712.2989003537274, 712.1736108341547, 1059.3028590671972, 1497.1111723262381, 2410.7281094659293, 4422.600003538069, 10639.153797050876, 21691.320766994926, 45971.68456375839, 91827.67235996327};
QuickSort = {780.2510673824163, 899.0357995655863, 1229.733878841987, 2115.2551030336876, 46303.74590239837, 115050.7630004602, 271829.77228260867, 603560.328106152, 1342529.6916890081, 2965269.349112426, 6622509.02631579, 1.5045565676470589*10^7};
SelectionSort = {1626.7971290340422, 5189.992121652481, 17446.351430565246, 63880.23454266735, 6390999.493670886, 2.6850240684210528*10^7, 1.068697138*10^8, 4.399030115*10^8, 1.784892424*10^9, 7.214766123*10^9, 3.0060269881*10^10,  1.35096492432*10^11};
Num = {10, 25, 50, 100, 1000, 2000, 4000, 8000, 16000, 32000, 64000, 128000};


They are tests I have performed with different sorting algorithms.

I have the following code to put all of them in a single plot.

ListLinePlot[
{
Table[{Num[[i]], HeapSort[[i]]}, {i, 12}],
Table[{Num[[i]], InsertSort[[i]]}, {i, 12}],
Table[{Num[[i]], MergeSort[[i]]}, {i, 12}],
Table[{Num[[i]], QuickSort[[i]]}, {i, 12}],
Table[{Num[[i]], SelectionSort[[i]]}, {i, 12}]
},
PlotLegend -> {"Heap Sort", "Insertion Sort", "Merge Sort",
"Quick Sort", "Selection Sort"}, LegendPosition -> {1, -0.25},
PlotMarkers -> Automatic,
PlotLabel -> "Average Time of Heap Sort",
AxesLabel -> {"Test Number", "Nano Seconds"},
ImageSize -> Large
]


For some reason, I can't get the plots to show up correctly. The x axis only goes up to around 80000. This is fixed when I remove all but one of the Table lists in the above code.

If you guys could help me debug this code and figure out what's wrong.

-
Works perfectly fine for me. Have you tried restarting the kernel and starting from scratch with this code? – jVincent Feb 25 at 0:37
Does PlotRange -> All option to ListLinePlot help? – Vitaliy Kaurov Feb 25 at 0:38
The PlotRange->All did help. I actually think I am going to be using the below answer. The graph will turn out much nicer I think. Also, the restart worked out great. I think something got caught up or something. – Milo Gertjejansen Feb 25 at 3:39

You may try:

ListLogPlot[Transpose /@ Reverse /@
Partition[
Riffle[{HeapSort, InsertSort, MergeSort, QuickSort, SelectionSort}, {Num}, {2, -1, 2}], 2],
PlotRange -> Full, Joined -> True]


-
 This graph looks great. Thanks! Just one thing though.. What happened to selection sort? There is only 4 lines on there when there should be 5. Edit: I added {} as a final list, so that it shows all 5 real ones. But what really went on here? Since this probably isn't proper behavior. – Milo Gertjejansen Feb 25 at 3:48 @MiloGertjejansen Sorry, I made a mistake with the Riffle functions. Corrected now. – belisarius Feb 25 at 4:01

Another option:

dat = {Num, #}\[Transpose] & /@
{HeapSort, InsertSort, MergeSort, QuickSort, SelectionSort};

ListLogLogPlot[dat,
PlotMarkers -> Automatic,
PlotLabel -> "Average Time of Heap Sort",
AxesLabel -> {"Test Number", "Nano Seconds"},
ImageSize -> Large,
Joined -> True
]


-
 The plot title seems misleading – belisarius Feb 25 at 11:44 @belisarius No argument here. It's what the OP had in his so I left it. – Mr.Wizard♦ Feb 25 at 12:23 Hey! I haven't see it! sorry – belisarius Feb 25 at 12:24 Yeah, changed it in my work last night.. It should be Average Time of Sorts. – Milo Gertjejansen Feb 25 at 14:54 @Milo image changed accordingly. – Mr.Wizard♦ Feb 25 at 14:57

Also, you may plot them first. If you don't want to see them, simply add ; after the code. After plotting them all, use Show[a1,a2,……,an]. That's all.

With code:

ListLinePlot[Table[{Num[[i]], #[[i]]}, {i, 12}],
PlotMarkers -> Automatic, PlotLabel -> "Average Time of Heap Sort",
AxesLabel -> {"Test Number", "Nano Seconds"}, ImageSize -> Large] & /@
{HeapSort, InsertSort, MergeSort, QuickSort, SelectionSort};

Show[%]


-
 Welcome to the site! I'm not sure that this answer addresses any aspect of the OP's question, though? – Oleksandr R. Feb 25 at 9:44 Ok,+1 after @Mr.Wizard's edit. – belisarius Feb 25 at 12:36