0
$\begingroup$

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
$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Mr.Wizard Feb 4 '13 at 13:08
  • $\begingroup$ @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 $\endgroup$ – JohnnyM Feb 4 '13 at 13:53
2
$\begingroup$
 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]

enter image description here

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]]

enter image description here

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – JohnnyM Feb 4 '13 at 13:57
  • $\begingroup$ @JohnnyM, x and y indices need not be consecutive; ListPlot3D also takes data in the form {{x1,y1,z1},{x2,y2,z2}...}. $\endgroup$ – kglr Feb 4 '13 at 14:10
  • $\begingroup$ @kugler can you please update your answer so it would generate data in this format? $\endgroup$ – JohnnyM Feb 4 '13 at 14:14
  • $\begingroup$ @JohnnyM, please see my update. $\endgroup$ – kglr Feb 4 '13 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.