I have 2 data sets, data1
and data2
with large (in the thousands) amounts of data
and I want to compare them
in a plane. They aren't modeled by the normal distribution, but I'm
using that here for simplicity.
data1 = RandomReal[NormalDistribution[], {10000, 2}];
data2 = data1+1;
I can put these on a list plot and plot them. However, this is visually unpleasing and even hides some of the data.
combPlot = ListPlot[{data1, data2},
PlotRange->All,
PlotStyle->PointSize[0.01],
PlotStyle->Directive[Opacity[0.5]]
];
Export[Directory[] <> "/figures/test-comb.pdf", combPlot];
The SmoothDensityHistogram
command with the following color function shows the data exactly how I want it for each data set.
histOpts = {ColorFunction -> Function[c, GrayLevel[1 - c]],
PlotRange -> {{-4, 4}, {-4, 4}}, ImageSize -> Medium};
hist1 = SmoothDensityHistogram[data1, histOpts];
Export[Directory[] <> "/figures/test-hist1.pdf", hist1];
hist2 = SmoothDensityHistogram[data2, histOpts];
Export[Directory[] <> "/figures/test-hist2.pdf", hist2];
How can I combine these into a single plot, preferably with different colors? I had no success using the Show
command. Again, the idea is to visually compare the 2 data sets. If there are any other alternatives, I'd like to see them too.
Update: After seeing Diego Zviovich's post, I was able to get it working for my example. However, my actual data sets may significantly differ so the bounds aren't the same:
data1 = RandomReal[NormalDistribution[], {10000, 2}];
data2 = data1+10;
hist1 = SmoothDensityHistogram[data1,
ColorFunction->Function[c, Hue[215/360, .973, 1, c]],
PlotRange->All, ImageSize -> Medium];
hist2 = SmoothDensityHistogram[data2,
ColorFunction->Function[c, Hue[311/360, .973, 1, c]],
PlotRange->All, ImageSize -> Medium];
combHist = Show[
Rasterize[hist1],
Rasterize[hist2],
PlotRange->All
];
Export[Directory[] <> "/figures/test-hist1.pdf", hist1];
Export[Directory[] <> "/figures/test-hist2.pdf", hist2];
Export[Directory[] <> "/figures/test-combHist.pdf", combHist];
data1:
data2:
Combined:
How do I correct the bounds for this?
Update: Using m_goldberg's suggestion, I'm able to get what I want:
I'll leave this opened for a little for any further discussion, but I'm satisfied with this now. Thanks to everyone who helped!
Further update (sorry): I'm a little unsatisfied with the results for my actual data. The first one appears fine, but the second is overly distorted:
Does anybody have any further suggestions for these?
Show
to act as I expect here? $\endgroup$