# Export Density plot Counts or Intensity array values

I have the following code:

plot1 = Show[DensityHistogram[data, 100, "Count",
PlotRange -> {{0, 200}, {0, 200}}, ColorFunction -> "Rainbow",
ChartLegends -> Automatic which I would like to export as an array of numbers and reproduce the original image with ArrayPlot function. As the range is 200x200, the array should be of the same size to represent the whole range. Is there a way to get this array? This question is consequence of the precedent post Export a density plot as a columns and rows numbers

• whats wrong with HistogramList ? – george2079 Sep 12 '17 at 17:04

SeedRandom
data = RandomVariate[BinormalDistribution[{10, 10}, {5, 5}, .5], 1000];


You can use HistogramList using the same binspec you used in DensityHistogram as the second argument:

{bins, heights} = HistogramList[data, 20];

Row[{dp = DensityHistogram[data, 20, "Count", ColorFunction -> "Rainbow",
Frame -> True,   ImageSize -> 400],
ArrayPlot[Reverse@Transpose@heights, Frame -> True,
FrameTicks -> {{Automatic, None}, {Automatic, None}},
DataRange -> PlotRange[dp], ColorRules -> {0 -> White},
ColorFunction -> "Rainbow", ImageSize -> 400]}] Note the use of option DataRange in ArrayPlot. Without it, ArrayPlot assumes the x and y values are row and column indices of the input array. The correct setting for this option can be obtained in several ways:

PlotRange[dp]


{{-4., 26.}, {-6., 24.}}

PlotRange /. Options[dp, PlotRange]


{{-4., 26.}, {-6., 24.}}

Or using bins obtained from HistogramList:

 MinMax /@ bins (* Through[{Min, Max}@#] & /@ bins for version 9 and earlier*)


{{-4, 26}, {-6, 24}}

• If I want to Export the array of count or intensity values but only a selected range, could I use HistogramList[data,{0,200,20},"Count"]? – user1993416 Sep 12 '17 at 17:24
• @user1993416, i think it should work. – kglr Sep 12 '17 at 17:29