Questions on `hist | Makie`

hist | Makie can draw multiple histograms on one figure like what follows

But I wonder if these histograms share a same height scale so that we can compare between different histograms according to the bar heights. To make it more clear, let’s take the following example where there is only one bar for each histogram,

fig = Figure()
ax = Axis(fig[1, 1])
for i in 1:5
    if i != 5
        hist!(ax, randn(1000), scale_to=-0.6, offset=i, direction=:x, bins=1)
    else
        hist!(ax, randn(10), scale_to=-0.6, offset=i, direction=:x, bins=1)
    end
end
fig

image

Since here the height (or the horizontal width) of the bar reflects the sample size, we expect the last bar should be shorter than the others (99/100 shorter) but it isn’t. Is there anyone who knows how to achieve this goal?

Thanks!

I also want to ask how to make the histograms have a same bar width instead of a same number of bars.

image

Thanks!

You can pass a list of bin edges as the bins argument:

fig = Figure()
ax = Axis(fig[1,1])
hist!(ax, rand(1000), bins=0:0.1:2)
hist!(ax,  2 * rand(1000), bins=0:0.1:2)

You are manually setting the height with the scale_to argument:

scale_to

Allows to scale all values to a certain height.

Consequently, you can compare two histograms only by the relative weights.

I don’t think you can do that this way. If the histograms are supposed to display absolute frequencies (not relative), then I would say that this way of visualization (many histograms distributed along the horizontal axis) is not suitable.

1 Like

There’s different normalization modes for the histogram

1 Like

Yes. But actually I don’t quite understand from the doc what exactly scale_to=-0.6 means. Does that mean it scales all the highest bars of different histograms to a same absolute height (0.6) , or it just scales the histograms to 0.6 of their own default settings?

Seems fairly obvious what it does from just using it:

julia> using GLMakie

julia> hist(rand(1_000), scale_to = 1.5)

image

1 Like

I want to visualize 3 random variables following time-varying distributions on one figure. I hope to compare them from both time and space perspectives.

I hope hist should allow the user to set the ylim

limits are an axis property, not a property of the plot type. But you don’t have to hope, you can just do it:

julia> hist(rand(1_000); scale_to = 1.5,  axis = (;limits = (nothing, nothing, 0.0, 2.0)))

image

1 Like

Good😀

But it can’t be used here:


fig = Figure()
ax = Axis(fig[1, 1])
for i in 1:5
    if i != 5
        hist!(ax, randn(1000), scale_to=-0.6, offset=i, direction=:x, bins=1, axis = (;limits = (nothing, nothing, 0.0, 2.0)))
    else
        hist!(ax, randn(10), scale_to=-0.6, offset=i, direction=:x, bins=1, axis = (;limits = (nothing, nothing, 0.0, 2.0)))
    end
end
fig

Is there more detailed explanation on these terms? I can’t understand them explicitly for now. :woozy_face:

What is the error you are seeing? If it’s the same error I’m seeing it tells you exactly what’s going on and why this doesn’t work:

ERROR: ArgumentError: You cannot pass `axis` as a keyword argument 
to this plotting function. 
Note that `axis` can only be passed to non-mutating plotting functions
(not ending with a `!`) that implicitly create an axis, and `figure` 
only to those that implicitly create a `Figure`.

Yes, it’s the same. So I can’t achieve my goal in this way.

violin | Makie
Does anyone know, if the scale of violin plots is consistent? (i.e., is it comparable between multiple violin plots of the same figure?)