# Histogram bars become line when many observations?

**URL:** https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639
**Category:** Visualization
**Tags:** question, plotting
**Created:** [December 23, 2019, 11:28pm UTC](https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639 "2019-12-23T23:28:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pearlzli](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@pearlzli](https://discourse.julialang.org/u/pearlzli)
#### Post date: [December 23, 2019, 11:28pm UTC](https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639/1 "2019-12-23T23:28:08Z")

</div>

I noticed that when there are a lot of (e.g. 10 million) observations, `histogram` produces a line plot instead of a bar plot:

```julia
using Distributions, StatsPlots
x = rand(Normal(), 1_000_000)
histogram(x, bins = -5:0.2:5, label = "x")
savefig("x.png")

```

![x](https://global.discourse-cdn.com/julialang/original/3X/8/4/8469925208543e0ef83086f63482c8442f775678.png)

```julia
y = rand(Normal(), 10_000_000)
histogram(y, bins = -5:0.2:5, label = "y")
savefig("y.png")

```

![y](https://global.discourse-cdn.com/julialang/original/3X/8/f/8f46f8c70c201198960a1e4b23e6ee836a392496.png)

The same thing happens when I pass in `normalize = true`. Is this behavior intentional? Is there a way to turn it off, i.e. force there to be bars? I’m using Distributions v0.21.11 and StatsPlots v0.13.0.

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [December 23, 2019, 11:39pm UTC](https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639/2 "2019-12-23T23:39:49Z")

</div>

It does not look like it  
[https://github.com/JuliaPlots/Plots.jl/blob/3459bcd81766f71ba6ff0d185bf9e32cc5425521/src/recipes.jl#L679](https://github.com/JuliaPlots/Plots.jl/blob/3459bcd81766f71ba6ff0d185bf9e32cc5425521/src/recipes.jl#L679)  
Maybe you can manually specify seriestype to be barhist instead of calling histogram?

---

<div class="post-metadata">

### Author: ![pearlzli](https://avatars.discourse-cdn.com/v4/letter/p/76d3ee/32.png) [@pearlzli](https://discourse.julialang.org/u/pearlzli)
#### Post date: [December 24, 2019, 12:03am UTC](https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639/3 "2019-12-24T00:03:02Z")

</div>

Yes, calling `plot(x, seriestype = :barhist)` did it for me - thanks!

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [December 24, 2019, 12:09am UTC](https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639/4 "2019-12-24T00:09:29Z")

</div>

Exactly. It’s a bit of an overmagic compromise stemming from that me and @oschulz couldn’t agree on which of those two should be the default, coming from scientific fields with very different usual `n`.

---

<div class="post-metadata">

### Author: ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)
#### Post date: [December 25, 2019, 1:24pm UTC](https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639/6 "2019-12-25T13:24:49Z")

</div>

Yes - I had originally proposed to use stephist as the default, because it works for few and very many bins, but bar-style histograms seemed to be too popular to not make them the default. But maybe this magic should depend on the number of bins, not the number of observations? @mkborregaard, what do you think?

The ideal solution, long term, would be to have something like a filled step hist with lines between the bins as the default, and make the lines between the bins thinner/weaker as the bin count increases, until they finally vanish if there are very many bins. This way, we’d have a smooth transition between both styles as the default.

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [December 26, 2019, 11:38am UTC](https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639/7 "2019-12-26T11:38:53Z")

</div>

I agree it’s better to bar it on the number of bins, but in the current implementation the series type is chosen before autobins are calculated

---

<div class="post-metadata">

### Author: ![oschulz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oschulz/32/2998_2.png) [@oschulz](https://discourse.julialang.org/u/oschulz)
#### Post date: [December 27, 2019, 1:26pm UTC](https://discourse.julialang.org/t/histogram-bars-become-line-when-many-observations/32639/8 "2019-12-27T13:26:46Z")

</div>

> in the current implementation the series type is chosen before autobins are calculated

Ah, right, that was the reason!
