Why do the density plots with Unitful display units on the "wrong" axis?

bertulli
Thu, 19 Feb 2026 13:38:56 +0000
Visualization

Hi all! I noticed that, when plotting the probability distribution of some data with Plots.jl with density(x), the axis representing the “underlying” data, is on the x axis:

using Plots
using StatsPlots
x = [1,1,1,2,2]
density(x)

If we use Unitful.jl, that has recipes for plotting, we get:

using Plots
using StatsPlots
using Unitful
x = [1,1,1,2,2] .* u"m"
density(x)

You’ll see that the additional label of the unit (in this case “m”) is shown on the y-axis. Is there a reason, or is it a bug? Thanks!

Appendix: Note that for histogram(x) it is correctly displayed on the x axis:

1 post - 1 participant