# Export data of a 3D histogram

I want to export the data of a three dimensional histogram in the format

#   x     y     z


with a blank line between different lines, so that one can plot the histogram in gnuplot simply using

splot 'data.dat' u 1:2:3 w l


What is the right way to obtain that?

-
Can you use this? stackoverflow.com/questions/8696159/… –  Pickett Dec 4 '13 at 17:06
You could add some code to generate the data you refer to. It should be a fairly trivial task for Export - did you already try something along this line? –  Yves Klett Dec 4 '13 at 17:19

this is how you get your data..

example =
Transpose@{RandomVariate[NormalDistribution[0, 1], 1000],
RandomVariate[NormalDistribution[0, 2], 1000]};
Histogram3D[example]
list = HistogramList[example];
x = list[[1, 1]];
y = list[[1, 2]];
data = Flatten[
MapIndexed[ {x[[#2[[1]]]], y[[#2[[2]]]], #1} &, list[[2]] , {2}], 1];
ListPlot3D[data]


now exporting to a gnuplot form..

Export["test.txt", data // N, "Table"]


I dont have gnuplot on this machine to test but it should be close

Edit.. generalization to higher dimensions:

dim = TensorRank[Last@list];
data = Flatten[MapIndexed[
Append[Table[(First@list)[[k, #2[[k]]]], {k, dim}], #1] &,
Last@list ,{dim}], dim - 1];


Export["test.txt",