jvm.97
jvm.97

Reputation: 247

How can I get the same bin size for both groups in a histogram? (Julia)

I have two data sets and i want to plot them in a histogram. I want to have the same bin size for both of them, is there an easy way to do it? (Julia)

Upvotes: 2

Views: 1237

Answers (1)

Benoit Pasquier
Benoit Pasquier

Reputation: 3015

Define the bins yourself because otherwise whichever plotting package your are using likely has a heuristic to define the bins for you (so 2 different datasets might result in 2 different sets of bins).

For example, with Plots.jl:

using Plots
bins = -3:0.2:3
datasets = (randn(1000), rand(1000))
plot((histogram(d; bins) for d in datasets)...) # note the specified bins

will give a histogram for each dataset with the same bins:

enter image description here

Upvotes: 3

Related Questions