Group Abstract Group Abstract

Message Boards Message Boards

How do I set the range for Histogram[]?

I want to create multiple histograms of different data sets but with the same range for comparison. How do I do it? I want the binning and height scales to be automatic for the each set. But I want the range to be uniform among the histograms.

POSTED BY: Jay Gourley
4 Replies
Posted 4 years ago
POSTED BY: Jim Baldwin
Posted 4 years ago

Hi Jay,

Do you mean something like this?

d1 = RandomVariate[NormalDistribution[0, 1], 200];
d2 = RandomVariate[NormalDistribution[4, 1], 200];
d3 = RandomVariate[NormalDistribution[-4, 1], 200];

Histogram[{d1, d2, d3}]

enter image description here

If not, can you provide a specific example illustrating what you are looking for.

POSTED BY: Rohit Namjoshi
Posted 4 years ago
Finding the joint range of values is one way with adding in a little flexibility.

SeedRandom[12345];
data1 = RandomVariate[NormalDistribution[0, 1], 100];
data2 = RandomVariate[NormalDistribution[5, 3], 200];
(* Get minimum and maximum of all datasets combined *)
{xmin, xmax} = MinMax[Join[data1, data2]];
(* Allow for some flexibility *)
xlow = xmin - 0.1 (xmax - xmin);
xhigh = xmax + 0.1 (xmax - xmin);
Histogram[data1, Automatic, PlotRange -> {{xlow, xhigh}, Automatic}]
Histogram[data2, Automatic, PlotRange -> {{xlow, xhigh}, Automatic}]

Two histograms with the same horizontal range.

POSTED BY: Jim Baldwin

Perfect, Jim. Thanks.

POSTED BY: Jay Gourley
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard