Issue with misaligned x-axis in multiple histograms in CairoMakie

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.

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

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

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

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)

1 Like

It works!. Thank you so much