# Questions on \`hist | Makie\`

**URL:** <https://discourse.julialang.org/t/questions-on-hist-makie/116347>\
**Category:** Visualization\
**Tags:** question, package, makie\
**Created:** [June 28, 2024, 9:36am UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347 "2024-06-28T09:36:27Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 9:36am UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/1 "2024-06-28T09:36:27Z")

</div>

[hist | Makie](https://docs.makie.org/v0.21/reference/plots/hist#Moving-histograms) can draw multiple histograms on one figure like what follows

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/7/0717a54377de55730f58a59ec7f9f36d933881b5.png)

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,

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/9/7/97bcf70d754108fb51e8f633bc0413cfc2a8ca35.png)

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!

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 9:41am UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/2 "2024-06-28T09:41:21Z")

</div>

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

![image](https://global.discourse-cdn.com/julialang/original/3X/a/7/a732690adcfdc85d5ca2e1298f83fd4d8af3e9d3.png)

Thanks!

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [June 28, 2024, 11:33am UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/3 "2024-06-28T11:33:10Z")

</div>

> [@WuSiren](#):
>
> I also want to ask how to make the histograms have a same bar width instead of a same number of bars.

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

```julia
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)

```

 ![test](https://global.discourse-cdn.com/julialang/original/3X/e/7/e78f611e0795157895f3b45a172dd308518a286f.png)

> [@WuSiren](#):
>
> 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.

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.

> [@WuSiren](#):
>
> Is there anyone who knows how to achieve this goal?

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 28, 2024, 12:08pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/4 "2024-06-28T12:08:26Z")

</div>

There’s different normalization modes for the histogram

> **[hist | Makie](https://docs.makie.org/stable/reference/plots/hist#normalization)**
>
> Create impressive data visualizations with Makie, the plotting ecosystem for the Julia language. Build aesthetic plots with beautiful customizable themes, control every last detail of publication quality vector graphics, assemble complex layouts and...

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 12:43pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/5 "2024-06-28T12:43:03Z")

</div>

> [@barucden](#):
>
> You are manually setting the height with the `scale_to` argument:
> 
> > scale\_to
> > 
> > Allows to scale all values to a certain height.

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?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 28, 2024, 1:05pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/6 "2024-06-28T13:05:55Z")

</div>

Seems fairly obvious what it does from just using it:

```julia
julia> using GLMakie

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

```

![image](https://global.discourse-cdn.com/julialang/original/3X/3/8/38385852dc0f134d0b2b1932c2742ceda509bee4.png)

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 1:08pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/7 "2024-06-28T13:08:09Z")

</div>

> [@barucden](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 1:16pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/8 "2024-06-28T13:16:35Z")

</div>

I hope `hist` should allow the user to set the `ylim`

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 28, 2024, 1:24pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/9 "2024-06-28T13:24:45Z")

</div>

`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
julia> hist(rand(1_000); scale_to = 1.5, axis = (;limits = (nothing, nothing, 0.0, 2.0)))

```

![image](https://global.discourse-cdn.com/julialang/original/3X/8/5/85cae1ba81ae3d272e295186c38c9138956fddbe.png)

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 1:30pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/10 "2024-06-28T13:30:19Z")

</div>

Good😀

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 2:58pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/11 "2024-06-28T14:58:07Z")

</div>

> [@nilshg](#):
>
> `limits` are an axis property, not a property of the plot type. But you don’t have to hope, you can just do it:

But it can’t be used here:

```julia

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

```

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 3:02pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/12 "2024-06-28T15:02:37Z")

</div>

> [@jules](#):
>
> There’s different normalization modes for the histogram

Is there more detailed explanation on [these terms](https://docs.makie.org/v0.21/reference/plots/hist#normalization)? I can’t understand them explicitly for now. 🥴

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 28, 2024, 3:04pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/13 "2024-06-28T15:04:44Z")

</div>

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:

```julia
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`.

```

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 3:27pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/14 "2024-06-28T15:27:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)\
**Post date:** [June 28, 2024, 3:30pm UTC](https://discourse.julialang.org/t/questions-on-hist-makie/116347/15 "2024-06-28T15:30:03Z")

</div>

[violin | Makie](https://docs.makie.org/v0.21/reference/plots/violin#examples)  
Does anyone know, if the scale of violin plots is consistent? (i.e., is it comparable between multiple violin plots of the same figure?)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/e/5e12f7f405886a19859ebaca672c00be4309d77d.png)
