# Plot contours of a heatmap

**URL:** https://discourse.julialang.org/t/plot-contours-of-a-heatmap/37804
**Category:** General Usage
**Tags:** plotting
**Created:** [April 18, 2020, 1:06pm UTC](https://discourse.julialang.org/t/plot-contours-of-a-heatmap/37804 "2020-04-18T13:06:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [April 18, 2020, 1:06pm UTC](https://discourse.julialang.org/t/plot-contours-of-a-heatmap/37804/1 "2020-04-18T13:06:29Z")

</div>

I have this heatmap of a matrix with Integer values.

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

But it is best suited for continuous values, so I tried contour instead but the contour links the center of the squares like this:

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

Is there an easy way to trace the contours that you see in the heatmap ?

---

<div class="post-metadata">

### Author: ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)
#### Post date: [April 18, 2020, 1:36pm UTC](https://discourse.julialang.org/t/plot-contours-of-a-heatmap/37804/2 "2020-04-18T13:36:02Z")

</div>

This looks like Plots.jl, so I’ll assume you’re using that.  
For me, this makes smooth contours:

```julia
using Plots
A = [(x-5)*(y-5) for x=1:10,y=1:11]
contour(A, w=2, linecolor=:black, fill=true)

```

What version of Plots are you using? Which backend (default GR)? Can you provide a MWE? This makes it easier to help you.

---

<div class="post-metadata">

### Author: ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)
#### Post date: [April 18, 2020, 1:44pm UTC](https://discourse.julialang.org/t/plot-contours-of-a-heatmap/37804/3 "2020-04-18T13:44:14Z")

</div>

I’m using Plots 0.29.6 yes, with GR.

try this:

```julia
A = reshape([max(i,j) for i in 1:5 for j in 1:5],5,5)
heatmap(A)
contourf(A, levels = 1:5)

```

I would like contour to draw the same squares as the heatmap.

---

<div class="post-metadata">

### Author: ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)
#### Post date: [April 18, 2020, 11:30pm UTC](https://discourse.julialang.org/t/plot-contours-of-a-heatmap/37804/4 "2020-04-18T23:30:24Z")

</div>

Sorry for misunderstanding. I don’t know of a straightforward solution, but maybe you can use a hack like this:

```julia
using Plots

A = reshape([max(i,j) for i in 1:5 for j in 1:5],5,5)

function scale4plot(A,f=100)
    resize(A,f) = [A[i,j] for i=1 .+(0:f*size(A,1)-1).÷f,j=1 .+(0:f*size(A,2)-1).÷f]
    B = resize(A,f)
    ax,ay = ( (axes(B,i)./f).+0.5 for i=1:2)
    ay,ax,B
end
contour(scale4plot(A)..., w=1, linecolor=:black, fill=true )

```

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