# Discrete 3D plots of median ratios of two 2D matrices of lists of values

Lets say I have 2 2D arrays where each cell contains a list of values:

Example:

data_1[[1]][[1]] = {1,2,3}
data_1[[1]][[2]] = {1,2,3}
data_1[[2]][[1]] = {1,2,3}
data_1[[1]][[2]] = {1,2,3}

data_2[[1]][[1]] = {2,4,6}
data_2[[1]][[2]] = {3,6,9}
data_2[[2]][[1]] = {4,8,12}
data_2[[2]][[2]] = {5,10,15}


What's a neat way to make a discrete 3D plot of the ratio between medians of these data sets (assuming that the indices always mach, but can represent any value, not only consecutive natural numbers).For the following data I would expect a plot of:

x,y,z
1,1,2
1,2,3
2,1,4
2,2,5

• You cannot use underscore (_) in symbol names; it is reserved for patterns. Also, your format is confusing. Why don't you paste the complete nested list structure you are describing instead of the messy Set lines? Commented Feb 4, 2013 at 13:08
• @Mr.Wizard thx for the heads up about "_". I didn't paste it because I don't have it yet -> see my other question link Commented Feb 4, 2013 at 13:53

 dt1 = Array[RandomReal[1, {3}] &, {5, 5}];
dt2 = Array[RandomReal[1, {3}] &, {5, 5}];
{med1, med2} = Map[Median, #, {2}] & /@ {dt1, dt2};
medratios = med1/med2;
Row[ListPlot3D[#, BoxRatios -> 1, ImageSize -> 300] & /@ {med1, med2,  medratios},
Spacer[5]


Update: per op's request in the comments, here is a version that generates data of the form {{x,y,{z1,z2,z3}}...:

 dt1xyz = Array[{10 #1, 100 #2, RandomReal[1, {3}]} &, {5, 5}];
dt2xyz = Array[{10 #1, 100 #2, RandomReal[1, {3}]} &, {5, 5}];
med1xyz = dt1xyz;
med1xyz[[All, All, 3]] = Map[Median, med1xyz[[All, All, 3]], {2}];
med2xyz = dt2xyz;
med2xyz[[All, All, 3]] = Map[Median, med2xyz[[All, All, 3]], {2}];
ratiosxyz = dt2xyz;
ratiosxyz[[All, All, 3]] =
med1xyz[[All, All, 3]]/med2xyz[[All, All, 3]]


.. and plots:

 Row[ListPlot3D[#, BoxRatios -> 1, ImageSize -> 300] & /@ {Join @@
med1xyz, Join @@ med2xyz, Join @@ ratiosxyz}, Spacer[5]]


• will it handle non consecutive indices? like when x has step of 10 and y of 100; (data[[10]][[100]]). Are list suitable for this kind of indexing anyway? Commented Feb 4, 2013 at 13:57
• @JohnnyM, x and y indices need not be consecutive; ListPlot3D also takes data in the form {{x1,y1,z1},{x2,y2,z2}...}.
– kglr
Commented Feb 4, 2013 at 14:10
• @kugler can you please update your answer so it would generate data in this format? Commented Feb 4, 2013 at 14:14
• @JohnnyM, please see my update.
– kglr
Commented Feb 4, 2013 at 15:12