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

**URL:** <https://discourse.julialang.org/t/why-do-the-density-plots-with-unitful-display-units-on-the-wrong-axis/135727>\
**Category:** Visualization\
**Tags:** statistics, distributions, recipe, unitful\
**Created:** [February 19, 2026, 1:38pm UTC](https://discourse.julialang.org/t/why-do-the-density-plots-with-unitful-display-units-on-the-wrong-axis/135727 "2026-02-19T13:38:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bertulli](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Post date:** [February 19, 2026, 1:38pm UTC](https://discourse.julialang.org/t/why-do-the-density-plots-with-unitful-display-units-on-the-wrong-axis/135727/1 "2026-02-19T13:38:56Z")

</div>

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:

```julia-auto
using Plots
using StatsPlots
x = [1,1,1,2,2]
density(x)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/2/124a7a524a7fc86b386a48905dbe8d0023297159.png)

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

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

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/8/986dcd716213590b4882370b6b4723605dd2750d.png)  
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:

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