# Issue with misaligned x-axis in multiple histograms in CairoMakie

**URL:** https://discourse.julialang.org/t/issue-with-misaligned-x-axis-in-multiple-histograms-in-cairomakie/114002
**Category:** Visualization
**Tags:** plotting, makie
**Created:** [May 8, 2024, 2:26pm UTC](https://discourse.julialang.org/t/issue-with-misaligned-x-axis-in-multiple-histograms-in-cairomakie/114002 "2024-05-08T14:26:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![indymnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/indymnv/32/212594_2.png) [@indymnv](https://discourse.julialang.org/u/indymnv)
#### Post date: [May 8, 2024, 2:26pm UTC](https://discourse.julialang.org/t/issue-with-misaligned-x-axis-in-multiple-histograms-in-cairomakie/114002/1 "2024-05-08T14:26:57Z")

</div>

I’m trying to create histograms to represent time, with a specific dataframe and I’ve noticed that in some cases the X-axis isn’t properly adjusted with the interval separation and its respective axis.

```julia
fig2 = Figure()
ax1 = Axis(fig2[1, 1]; ylabel="Frequencia", title = "Nov 2023",xticks = (0:3:24) ,xgridvisible = false, ygridvisible = false)
ax2 = Axis(fig2[1, 2]; title = "Dic 2023",xticks = (0:3:24),xgridvisible = false, ygridvisible = false)
ax3 = Axis(fig2[2, 1]; ylabel="Frequencia", title = "Ene 2024",xticks = (0:3:24),xgridvisible = false, ygridvisible = false)
ax4 = Axis(fig2[2, 2]; title = "Feb 2024",xticks = (0:3:24),xgridvisible = false, ygridvisible = false)
ax5 = Axis(fig2[3, 1]; xlabel="Hora", ylabel="Frequencia", title = "Mar 2024",xticks = (0:3:24),xgridvisible = false, ygridvisible = false)
ax6 = Axis(fig2[3, 2]; xlabel="Hora", title = "Abr 2024",xticks = (0:3:24),xgridvisible = false, ygridvisible = false)

hist!(ax1, filter(row -> row.Month == months[1], df_filter).Hour_cont, bins=8,strokecolor= :black,strokewidth = 1, xticksvisible=false)
hist!(ax2, filter(row -> row.Month == months[2], df_filter).Hour_cont, bins=8,strokecolor= :black,strokewidth = 1)
hist!(ax3, filter(row -> row.Month == months[3], df_filter).Hour_cont, bins=8,strokecolor= :black,strokewidth = 1)
hist!(ax4, filter(row -> row.Month == months[4], df_filter).Hour_cont, bins=8,strokecolor= :black,strokewidth = 1)
hist!(ax5, filter(row -> row.Month == months[5], df_filter).Hour_cont, bins=8,strokecolor= :black,strokewidth = 1)
hist!(ax6, filter(row -> row.Month == months[6], df_filter).Hour_cont, bins=8,strokecolor= :black,strokewidth = 1)

fig2

```

Notice the last plot (Abr 2024) is not correctly aligned

 ![total_month](https://global.discourse-cdn.com/julialang/original/3X/b/6/b6c347a568488707b22e048881fca42702f957df.png)

I also noticed that in some specific histograms where there was an empty interval, the same issue occurs. Here another example:

 ![total_by_emer](https://global.discourse-cdn.com/julialang/original/3X/1/e/1ebfd84916ba8e032cb8cb3d70e0cc6f93f928bb.png)

Has anyone encountered a similar issue or knows how to adjust it?

---

<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: [May 8, 2024, 2:36pm UTC](https://discourse.julialang.org/t/issue-with-misaligned-x-axis-in-multiple-histograms-in-cairomakie/114002/2 "2024-05-08T14:36:17Z")

</div>

When you say `bins = 8` that just means eight bins over the data range seen. The hist objects don’t communicate their ranges to each other so if one has a smaller range, the bins will differ. You can instead compute your own bin edges and pass those to the `bins` argument, for example `range(extrema(all_data)..., length = 9)`

---

<div class="post-metadata">

### Author: ![indymnv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/indymnv/32/212594_2.png) [@indymnv](https://discourse.julialang.org/u/indymnv)
#### Post date: [May 8, 2024, 2:53pm UTC](https://discourse.julialang.org/t/issue-with-misaligned-x-axis-in-multiple-histograms-in-cairomakie/114002/3 "2024-05-08T14:53:04Z")

</div>

It works!. Thank you so much
