When I tried to present some pre-calculated density histograms inside Manipulate I noticed that the display of DensityHistogram
is extremely slow. Here is a simple benchmark:
Second[x_] := x[[2]];
data = RandomVariate[BinormalDistribution[Abs@Random[]], {5, 10^4}];
histograms =
DensityHistogram[#, 30, PerformanceGoal -> "Speed"] & /@
data;
contourplots =
ListContourPlot[Second@HistogramList[#, 30],
InterpolationOrder -> 0] & /@ data;
rasterizedSmall = Rasterize[#, ImageSize -> Small] & /@ histograms;
rasterizedMedium = Rasterize[#, ImageSize -> Medium] & /@ histograms;
t = AbsoluteTime[];
histograms
AbsoluteTime[] - t
(* ==> 1.6410939 *)
t = AbsoluteTime[];
contourplots
AbsoluteTime[] - t
(* ==> 0.0860049 *)
t = AbsoluteTime[];
rasterizedSmall
AbsoluteTime[] - t
(* ==> 0.0390022 *)
t = AbsoluteTime[];
rasterizedMedium
AbsoluteTime[] - t
(* ==> 0.0280016 *)
So we see that it takes almost two seconds to display five pre-calculated density histograms, while five list contour plots are displayed in ~100 ms.
What is wrong and is there an easy way to fix it?
(I'm using mma 8.0.1 on Win 7 and I've already turned off antialising)