# Histogram in Julia

**URL:** <https://discourse.julialang.org/t/histogram-in-julia/12265>\
**Category:** General Usage\
**Created:** [July 9, 2018, 2:34am UTC](https://discourse.julialang.org/t/histogram-in-julia/12265 "2018-07-09T02:34:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![microlifecc](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@microlifecc](https://discourse.julialang.org/u/microlifecc)\
**Post date:** [July 9, 2018, 2:34am UTC](https://discourse.julialang.org/t/histogram-in-julia/12265/1 "2018-07-09T02:34:12Z")

</div>

I did:

```julia
edges, counts = imhist(imgG,8);
plot(edges, counts, label="line") ;
scatter!(edges, counts, label="points");
xlabel!("Intensities");
ylabel!("Counts");
title!("Hist");

```

imgG is a grayscale image.

I am getting an error:

> BoundsError: attempt to access 6-element Array{Float64,1} at index [1:7]

I am using plotlyjs.

Any help plz? Thanks!

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [July 9, 2018, 3:19am UTC](https://discourse.julialang.org/t/histogram-in-julia/12265/2 "2018-07-09T03:19:21Z")

</div>

Please provide a minimum working example.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [July 9, 2018, 4:10am UTC](https://discourse.julialang.org/t/histogram-in-julia/12265/3 "2018-07-09T04:10:16Z")

</div>

Ordinarily one might say RTFM, but I have some sympathy here: `Images.imhist` is pointlessly painful to use. It gives the interior portion of an array  
`[-Inf, edges[1],...,edges[end],Inf]`

So try using this instead of `edges` in your plot calls:

```julia
plotvals = midpoints([minimum(imgG[:]),edges...,maximum(imgG[:])])

```
