This is actually a very simple scenario, in order to make simpler this question Part I.
Consider the following piece of Mathematica code
data1 = {{-1, 2}, {3, 1}};
data2 = {{1, -5}, {2, -1}};
data3 = {{0, 1}, {-3, 4}};
data4 = {{-4, 9}, {8, 10}};
data5 = {{-2, 5}, {-2, -5}};
data6 = {{-5, -3}, {0, 1}};
data7 = {{-1, -2}, {-1, 1}};
data8 = {{2, 9}, {7, 1}};
L1 = ListPlot[data1];
L2 = ListPlot[data2];
L3 = ListPlot[data3];
L4 = ListPlot[data4];
L5 = ListPlot[data5];
L6 = ListPlot[data6];
L7 = ListPlot[data7];
L8 = ListPlot[data8];
P0 = GraphicsGrid[{{L1, L2, L3}, {L4, L5, L6}, {L7, L8}}, ImageSize -> 550]
The simple two elements lists could be massive external data files. So, my question is: If I don't know the exact number of data files beforehand (in my case for example, it could be anything between 0 and 8), how can I define the GraphicsGrid
? If a list (file) is missing then I will get an empty slot in the grid. Is it possible to fit the empty slot with the next available item, but maintaining the grids's original structure (3 rows, the first 2 with 3 plots per row and the last one with only 2 plots)?
EDIT
I see that the use of lists is not helpful because it does not match to the actual case. So, let me explain the situation: I run a FORTRAN program which produces 8 data files. However, there are cases in which the number of produced files is smaller than 8, even zero but never larger than 8. So in order to plot these files I constructed this code. However, many complained about this and for this reason let's suppose the following:
SetDirectory[];
data1 = Import["data1.ab","Table"];
data2 = Import["data2.cd","Table"];
data3 = Import["data3.ef","Table"];
data4 = Import["data4.gh","Table"];
data5 = Import["data5.ij","Table"];
data6 = Import["data6.kl","Table"];
data7 = Import["data7.mn","Table"];
data8 = Import["data8.op","Table"];
L1 = ListPlot[data1];
L2 = ListPlot[data2];
L3 = ListPlot[data3];
L4 = ListPlot[data4];
L5 = ListPlot[data5];
L6 = ListPlot[data6];
L7 = ListPlot[data7];
L8 = ListPlot[data8];
P0 = GraphicsGrid[{{L1, L2, L3}, {L4, L5, L6}, {L7, L8}}, ImageSize -> 550]
The structure of the grid corresponds to the case where all 8 files are present. What I want is an automatic procedure reading every available data file, determine which of them are present (not empty) and then plot them in a grid.
n
files ->n
plots. Where have you mentioned that you want the 20 plots as 4x4 and 2x2? "How hard can it be" — well, it's not that hard, but you're not making it easier... If you had spent 30 minutes improving/simplifying your MWE, you would've saved 9 hours of haggling with the commenters. Just sayin'... :) $\endgroup$n := RandomInteger[20]
as a blackbox "number of plots from data files" generator and refocus your question solely on how to automatically grid then
plots. $\endgroup$