# Bin behaviour in fit( Histogram, (x,y) ) |\> Plots.heatmap

**URL:** <https://discourse.julialang.org/t/bin-behaviour-in-fit-histogram-x-y-plots-heatmap/44963>\
**Category:** New to Julia\
**Tags:** question, plotting\
**Created:** [August 14, 2020, 9:59pm UTC](https://discourse.julialang.org/t/bin-behaviour-in-fit-histogram-x-y-plots-heatmap/44963 "2020-08-14T21:59:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [August 14, 2020, 9:59pm UTC](https://discourse.julialang.org/t/bin-behaviour-in-fit-histogram-x-y-plots-heatmap/44963/1 "2020-08-14T21:59:00Z")

</div>

Hi,  
I would to ask for your support with this one.

I am fitting an 2d-histrogram to a tuple of vectors. Then, I try to heatmap it but I cannot make it work. Interestingly, for random data it works as it should. I cannot use histogram2d() cause I want to manipulate(filter) the 2d-histogram before plotting it.

My code:

```julia
df=CSV.read("path")
mybins=100
x=Vector(df[!,:A])
y=Vector(df[!,:B])
lenx=length(x) # equal to 2265
leny=length(y) # equal to 2265

h1=fit(Histogram,(x,y),closed=:left,nbins=mybins)
h1=normalize(h1,mode=:pdf)
p1=heatmap(h1.edges[1],h1.edges[2],h1.weights)

```

I obtain

```julia
Length of x & y does not match the size of z.
Must be either `size(z) == (length(y), length(x))` (x & y define midpoints)
or `size(z) == (length(y)+1, length(x)+1))` (x & y define edges).
error(::String) at error.jl:33

```

But then

```julia
h2=fit(Histogram,(rand(lenx),rand(leny)),closed=:left,nbins=mybins)
h2=normalize(h2,mode=:pdf)
p2=heatmap(h2.edges[1],h2.edges[2],h2.weights)

```

![myimage](https://global.discourse-cdn.com/julialang/original/3X/4/8/4875d67f6240f74f5d82952c54f2e0b34a3b49df.png)

My question: what am I missing?

Thank you

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [August 15, 2020, 12:55am UTC](https://discourse.julialang.org/t/bin-behaviour-in-fit-histogram-x-y-plots-heatmap/44963/2 "2020-08-15T00:55:55Z")

</div>

Are you sure the data read by CSV.read is right?

---

<div class="post-metadata">

**Author:** ![VMHidalgo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vmhidalgo/32/23055_2.png) [@VMHidalgo](https://discourse.julialang.org/u/VMHidalgo)\
**Post date:** [August 15, 2020, 1:10am UTC](https://discourse.julialang.org/t/bin-behaviour-in-fit-histogram-x-y-plots-heatmap/44963/3 "2020-08-15T01:10:55Z")

</div>

It is right, it is just a toy example.

Thank you
