# Makie matrix image display issue

**URL:** <https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281>\
**Category:** Visualization\
**Tags:** cairomakie\
**Created:** [November 30, 2024, 7:45am UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281 "2024-11-30T07:45:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)\
**Post date:** [November 30, 2024, 7:45am UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281/1 "2024-11-30T07:45:07Z")

</div>

Hi users

The following function `IMAGE_SU_A_METRIC`, using `Makie.jl` and `CairoMakie.jl` is meant to give an `image` of an input **matrix** `SU_A_METRX` using a couple of parameters from an input structure `STR_DTA_AMT`:

```julia
function IMAGE_SU_A_METRIC(SU_A_METRX, STR_DTA_AMT)
    M_HARM = STR_DTA_AMT.M_HARM
    N_HARM = STR_DTA_AMT.N_HARM
    F = Figure()
    ax = Axis(F[1,1])
    image!(F[1,1],
    SU_A_METRX, colormap = :lajolla100,
    interpolate = false)
    Colorbar(F[1,2],colormap =:lajolla100)
    ax.xticklabelsvisible = true
    ax.yticklabelsvisible = true
    ax.limits =(1, M_HARM, 1, N_HARM)
    ax.xticks = 1 : 10 : M_HARM
    ax.yticks = 1 : 10 : N_HARM
    F
end

```

The matrix `SU_A_METRX` is of size `M_HARM x N_HARM`. The relevant input parameters are here

```julia
julia> size(SU_AMT_51_31)
(51, 31)
julia> STR_DTA_AMT.M_HARM
51
julia> STR_DTA_AMT.N_HARM
31
julia> IMAGE_SU_A_METRIC(SU_AMT_51_31, STR_DTA_AMT)

```

which produces the image below (in a particular data case):

 ![1526601_LVL6](https://global.discourse-cdn.com/julialang/original/3X/b/8/b834cbaa2b88dae727a483bc5da2c4042dc8613e.jpeg)

The above image is fine except for one problem. It is an array of `50 x 30` cells rather than a `51 x 31` one. Thinking that I was inadvertently cropping the extreme row/ column , I’ve even tried with bigger limits `ax.xlimits = M_HARM+1` and `ax.ylimits = N_HARM+1` but that doesn’t solve it, other than giving out the same image as the above with one empty outer row and column of cells.

Need help/ clarity. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [November 30, 2024, 8:13am UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281/2 "2024-11-30T08:13:20Z")

</div>

The image starts at 0 so you’re cropping it on the other side than you were thinking

---

<div class="post-metadata">

**Author:** ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)\
**Post date:** [November 30, 2024, 10:22am UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281/3 "2024-11-30T10:22:17Z")

</div>

@jules

Thanks for the idea, but an image and its underlying matrix should be identical, no matter how indexed. A matrix of `2×2` size must be seen as `2×2` cells in the image.

And then, Julia matrix indexing begins from `1` and not `0`.

---

<div class="post-metadata">

**Author:** ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)\
**Post date:** [December 1, 2024, 5:22am UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281/4 "2024-12-01T05:22:44Z")

</div>

I solved it with a couple of mutation call changes, though by trial and error. The new function and its output are below.

```julia
function IMAGE_SU_A_METRIC(SU_A_METRX, STR_DTA_AMT)
    M_HARM = STR_DTA_AMT.M_HARM
    N_HARM = STR_DTA_AMT.N_HARM
    F = Figure()
    ax = Axis(F[1,1])
    image!(ax,
    SU_A_METRX, colormap = :lajolla100,
    interpolate = false)
    Colorbar(F[1,2],colormap =:lajolla100)
    ax.xticklabelsvisible = true
    ax.yticklabelsvisible = true
    ax.limits!=(1, M_HARM, 1, N_HARM)
    ax.xticks = 1 : 10 : M_HARM
    ax.yticks = 1 : 10 : N_HARM
    F
end

```

 ![1526601_LVL6_CORRECT_LIMITS](https://global.discourse-cdn.com/julialang/original/3X/a/8/a8e8275d61a1bf9c7cde12180b3201fec710ebb5.jpeg)

As one could see, the change was `ax.limits!` in place of `ax.limits`. But what I’m frustrated about is that the documentation doesn’t make it clear on why resetting axes limits would make it work correctly. Hope Makie’s developers would do something about bringing out clearer documentation like in Matlab, else all their good work could needlessly go ignored.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [December 1, 2024, 7:45am UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281/5 "2024-12-01T07:45:49Z")

</div>

I don’t know why that doesn’t error because `ax.limits!` doesn’t exist but in effect you’re not setting any limits which makes my previous suggestion go into effect. Your limits start at 0 now so you can see all the pixels. This has nothing to do with indices being 1-based in Julia. The image plot is considered to lie on a “quad” which is just a rectangle stretched over part of the data space. And by default that rectangle goes from 0 to n\_pixels on each side.

You can alternatively try `heatmap` which is cell-based so you’ll get one cell centered on the numbers from 1 to n by default which seems to be the representation you want.

---

<div class="post-metadata">

**Author:** ![Bananthahally](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bananthahally/32/222983_2.png) [@Bananthahally](https://discourse.julialang.org/u/Bananthahally)\
**Post date:** [December 1, 2024, 10:38am UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281/6 "2024-12-01T10:38:41Z")

</div>

Not quite right, @jules.

`ax.limits!` is very much a valid `mutation` to the `ax.limits` option. See the screenshot from the Makie docs webpage below.

 ![Screenshot_20241201_155720_Chrome](https://global.discourse-cdn.com/julialang/original/3X/4/2/42084d5128ba3894da69b5c191fc30b4c4c26bce.jpeg)

And oh yes, I’ve tried `heatmap` before settling onto `image`. `image` is what’s recommended because `heatmap` rendering takes longer. In regard to my issue though, `heatmap` produced nothing different.

Julia indexing (matrix or image) is never from `0` and always from `1`. The docs clarify this.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [December 1, 2024, 12:11pm UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281/7 "2024-12-01T12:11:32Z")

</div>

> [@Bananthahally](#):
>
> `ax.limits!` is very much a valid `mutation` to the `ax.limits` option.

It is not, the docs are talking about the `limits!` function which is an alternative to setting `ax.limits` directly, which is the usual way to change attributes. In that sense all attributes are already “mutating”, so they don’t need `!` variants.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [December 1, 2024, 12:16pm UTC](https://discourse.julialang.org/t/makie-matrix-image-display-issue/123281/8 "2024-12-01T12:16:12Z")

</div>

> [@Bananthahally](#):
>
> In regard to my issue though, `heatmap` produced nothing different.

Because you were setting your limits such that they cut off part of the data. I’m not sure why you were setting them in the first place
