# Is there a way to make a bihistogram plot?

Is there a way of making a bihistogram plot in mathematica?

There is a reference to it at http://mathworld.wolfram.com/Bihistogram.html but no suggestions as to how to do it.

data1 = RandomVariate[NormalDistribution[0, 1], 1000];
data2 = RandomVariate[NormalDistribution[0.3, 1], 1000];


One way is PairedHistogram

PairedHistogram[data1, data2]


A different layout can be achieved by hacking the height specification of Histogram.

Show[
Histogram[data1, Automatic],
Histogram[data2, Automatic, -#2 &]
]


Update

In practice, we often deal with datasets of different sizes. Thus instead of the "Count" height specification, we may want "PDF" or something else.

Here I provide explicit functions for some of the usual height specifications.

count = #2;
pdf = -(#2/(Total[#2] Subtract @@@ #1)) &;
probability = #2/Total[#2] &;
intensity = -(#2/Subtract @@@ #1) &;


These correspond exactly to the specifications "Count", "PDF", "Probability" and "Intensity", but they are expressed as a function, so we can easily put a minus sign in front to flip the bars.

Example with datasets of different sizes:

data1 = RandomVariate[NormalDistribution[0, 1.5], 1000];
data2 = RandomVariate[NormalDistribution[1, 0.7], 10000];

bs = 0.2; (* manually fixed bin size *)
Show[
Histogram[data1, {bs}, pdf (* or "PDF" *)],
Histogram[data2, {bs}, -pdf[##] &],
PlotRange -> 0.7 {-1, 1} (*manual plot range to center axis *)
]


• I really like the Histogram hight specification solution! – Anton Antonov May 2 '16 at 14:20
• And a simple trick to get different colours in the second example (while using Mathematica's default palette) would be Show[Histogram[data1, Automatic], Histogram[{{}, data2}, Automatic, -#2 &]] – Martin Ender May 2 '16 at 15:22
• I think this will work very nicely. Thanks very much. One small additional question for the rotated plot -- how can I ensure that the bin width, height and range are the same for both histograms? – Peter Blunden May 3 '16 at 4:56
• The data I am plotting has one histogram that is higher and has a longer tail than the other one. I'd actually like the option of either centering the horizontal axis or adjusting it up or down. – Peter Blunden May 3 '16 at 5:03
• @PeterBlunden Use a manual bin(-size) specification for both to ensure the same bin size (second argument). You can use PlotRange in Show to set the vertical range (and thus set the visual location of the center axis which is at 0). – Szabolcs May 3 '16 at 7:35