# Can \`Plots.jl\` \`heatmap\` coordinates start at 1 instead of 0.5?

**URL:** <https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385>\
**Category:** General Usage\
**Tags:** plotting, plots\
**Created:** [November 17, 2022, 6:45am UTC](https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385 "2022-11-17T06:45:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [November 17, 2022, 6:45am UTC](https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385/1 "2022-11-17T06:45:18Z")

</div>

For example, I want to `heatmap` the following matrix:

```julia
julia> m = [
         1 1 -1 -1
        -1 -1 -1 1
         1 1 1 1
        -1 -1 1 1
       ]

using Plots

heatmap(m)

```

 ![without clip](https://global.discourse-cdn.com/julialang/original/3X/8/f/8f6aa4514cbf996310bed9908463376af463e6d2.jpeg)

But if I set `xlims` and `ylims`, the image will be be clipped from `1` to `4`, whereas the original plot starts from `0.5` to `4.5`. I know in Python you can [set `extent` to avoid this](https://stackoverflow.com/questions/49714222/can-matplotlib-imshow-coordinates-start-at-0-instead-of-0-5).

```julia
heatmap(m; xlims=extrema(axes(m, 1)), ylims=extrema(axes(m, 2)))

```

 ![with clip](https://global.discourse-cdn.com/julialang/original/3X/b/b/bba7c246928ebfd662c1a13ac7fb0db87299dec2.jpeg)

Is there a `Plots.jl` equivalent when I am not using `PyPlot`?

---

<div class="post-metadata">

**Author:** ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)\
**Post date:** [November 17, 2022, 8:50am UTC](https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385/2 "2022-11-17T08:50:12Z")

</div>

Maybe `heatmap(1.5:4.5, 1.5:4.5, m)` (although this is equivalent to nodal extents, not cells centers) ?

Please also see the discussions in [[BUG] image tick positions misplaced when specifying image axes · Issue #4158 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/4158).

---

<div class="post-metadata">

**Author:** ![singularitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/singularitti/32/17678_2.png) [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Post date:** [November 17, 2022, 9:00am UTC](https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385/3 "2022-11-17T09:00:06Z")

</div>

Thanks, I tried the following code and it works:

```julia
heatmap(m; xlims=extrema(axes(m, 1)) .+ (-0.5, 0.5), ylims=extrema(axes(m, 2)) .+ (-0.5, 0.5))

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/b/5bbabe74fa494603eda480262c4c938f9c6f726f.jpeg)

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 17, 2022, 1:01pm UTC](https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385/4 "2022-11-17T13:01:46Z")

</div>

This question is a bit more general and both limits, [0.5 4.5] or [1 4] are correct. It all depends on what we want. In GMT this has been called the [_grid vs pixel_ registration](https://docs.generic-mapping-tools.org/latest/cookbook/options.html?highlight=pixel+registration#pixel-registration) and in Geotiff it’s known by the _Pixel-is-area vs Pixel-is-point_. Next fig and the GMT link above describe more these two ways of storing grids and images coordinates.

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

In GMT.jl to get the [1 4] limits (that is, to use the grid registration) you’d do

```julia
imshow(mat2grid(m))

```

and

```julia
imshow(mat2grid(m, reg=1))

```

to get the [0.5 4.5]

---

<div class="post-metadata">

**Author:** ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)\
**Post date:** [November 17, 2022, 1:25pm UTC](https://discourse.julialang.org/t/can-plots-jl-heatmap-coordinates-start-at-1-instead-of-0-5/90385/5 "2022-11-17T13:25:27Z")

</div>

I agree that we should have a higher level abstraction in `Plots` for this.  
A `PR` would be very much welcome.
