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
:
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> 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):
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.
jules
2
The image starts at 0 so you’re cropping it on the other side than you were thinking
@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
.
I solved it with a couple of mutation call changes, though by trial and error. The new function and its output are below.
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
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.
jules
5
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.
1 Like
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.
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.
jules
7
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.
jules
8
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