# Weird histogram looking

**URL:** <https://discourse.julialang.org/t/weird-histogram-looking/130601>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [July 10, 2025, 10:09am UTC](https://discourse.julialang.org/t/weird-histogram-looking/130601 "2025-07-10T10:09:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elisadonati23](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elisadonati23/32/205472_2.png) [@elisadonati23](https://discourse.julialang.org/u/elisadonati23)\
**Post date:** [July 10, 2025, 10:09am UTC](https://discourse.julialang.org/t/weird-histogram-looking/130601/1 "2025-07-10T10:09:13Z")

</div>

Dear all,  
can someone help me to understand why I get this histogram?  
agent\_adults\_last is 1236145-element Vector{Float64} with balues between 7.0 and 25.0  
Never happened to me.

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

it seems that it is a large sample size limit, because this works:

```julia

gr()
histogram(agent_adults_last.Lw[1:1000000],
    bins=30
)

```

thank you

---

<div class="post-metadata">

**Author:** ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)\
**Post date:** [July 10, 2025, 10:28am UTC](https://discourse.julialang.org/t/weird-histogram-looking/130601/2 "2025-07-10T10:28:04Z")

</div>

Your issue is that it makes a line plot instead of bars ? I’ve noticed that before but I’m not sure if it’s a bug or a feature…

One solution is to do the plot yourself, which gives you full control on how the its made :

```julia
using StatsBase, Plots

data = randn(100_000)
bins = LinRange(-3,3,100)

h = fit(Histogram, data, bins)

x = h.edges[1][1:end-1]
y = h.weights

bar(x,y)

```

---

<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:** [July 10, 2025, 12:19pm UTC](https://discourse.julialang.org/t/weird-histogram-looking/130601/3 "2025-07-10T12:19:06Z")

</div>

I believe that’s a feature, although I can’t find where it’s defined as the whole Plots machinery is very opaque to me

I think the point is simply that the number of bins by default scales with the number of observations, and at some point you are basically getting a density plot rather than a histogram. That point is 1 million observations:

```julia
julia> histogram(randn(1_000_000))

```

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

```julia
julia> histogram(randn(1_000_001))

```

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

You can also see the benefit of this here - with lots of bins you have more bin edges than actual bins (although this is exaggerated here because I use `linewidth = 2` by default).

Of course this isn’t all that sensible if you set the number of bins yourself…

---

<div class="post-metadata">

**Author:** ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Post date:** [July 10, 2025, 8:16pm UTC](https://discourse.julialang.org/t/weird-histogram-looking/130601/4 "2025-07-10T20:16:31Z")

</div>

Basically your histogram got transformed into a `stephist`: [Histograms · Plots](https://docs.juliaplots.org/latest/series_types/histogram/#Other-Variations). I think it’s actually way cleaner than the usual filled-bars histogram when you have a lot of data, like from simulations. For me, it’s especially useful when I want to plot multiple potentially overlapping histograms. With the usual bars the plot quickly becomes cluttered because everything is overlapping, the bar edges obscure the actual bars etc.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 10, 2025, 8:29pm UTC](https://discourse.julialang.org/t/weird-histogram-looking/130601/5 "2025-07-10T20:29:50Z")

</div>

If you’re working with lots of histograms allow me to introduce you to [Makie Plotting · FHist.jl](https://moelf.github.io/FHist.jl/stable/notebooks/makie_plotting/)
