# Heatmap from Matrix with custom indices

**URL:** <https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596>\
**Category:** Visualization\
**Tags:** cartesianindices\
**Created:** [May 24, 2022, 3:22pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596 "2022-05-24T15:22:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 3:22pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/1 "2022-05-24T15:22:55Z")

</div>

Hello Community!

I have data like so  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/7/d7eddb4c9916ab177522c232ba9330613a98f398.png)

where I would like to visualise a heatmap of the TimeDiff\_mean column and the other two columns (representing a reticulation over geographical datapoints).

I have sought for one or another utility function that may help me quickly do this without avail and though all the information is there pretty explicitly my brain is now saturated and my custom attempts have failed me 😅.

Thank you!

---

<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:** [May 24, 2022, 3:41pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/2 "2022-05-24T15:41:01Z")

</div>

This may work. Have your data in a fie with `.xyz` extension and then do (need GMT.jl)

```julia
using GMT
G = grdconvert("/path/to/yourfile.xyz");
imshow(G)

```

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 3:53pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/3 "2022-05-24T15:53:17Z")

</div>

OMG! Homebrew installing it now… This looks very impressive and should prove very helpful for what I am looking to do!

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 4:18pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/4 "2022-05-24T16:18:25Z")

</div>

I’ve downloaded GMT and necessary dependencies, added the julia wrapper via

```julia
Pkg.add GMT
using GMT

```

but it can’t find `grdconvert`. I’ve also tried prefixing `GMT.grdconvert` What’s going on?

---

<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:** [May 24, 2022, 4:45pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/5 "2022-05-24T16:45:30Z")

</div>

I’m not in front of a computer right now so can’t confirm if missed porting the grdconvert module. When you did the first  
using GMT  
It did precompile, right? GMT.jl is working (well installed)

Try this

G = gmt(“grdconvert yourfile.xyz”)

There other options to do this, but this would be the simplest for your case.

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 5:52pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/6 "2022-05-24T17:52:46Z")

</div>

Yes, seemingly it did precompile just fine but it now throws an error when `using`: `during initialization of module Gdal` it turns out it could not load `~.julia/conda/3/lib/libgdal.30.dylib` The reason: `Incompatible library version: libgdal.30.dylib requires version 54.0.0 or later, but libpng16.16.37.0.dylib provides version 16.0.0` So I’ve `up`ed my package environment and reloaded everything anew but no cigar.

---

<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:** [May 24, 2022, 7:44pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/7 "2022-05-24T19:44:55Z")

</div>

That’s getting complicated. So you installed GMT with brew and next did a `] add GMT` (the equivalent with `Pkg`). In this case the brew installed version should have been detected and no automatic (via conda) installation should occur. But your error message makes think it was `~.julia/conda/3/lib/libgdal.30.dylib` or then some previous GDALlib was already there. Try to just unlink the brew GMT installation and try again to see the automatic one set correctly.

Regarding my recipe, it works fine. What happened is the `grdconvert` module seem to me that had no interest in the wrapper (it converts between grid formats of disk files) but it turns out that it’s very handy for this case where a GDAL function will guess the grid parameters when parsing the text file. I’ll add a wrapper to it but meanwhile this worked fine for me.

```julia
using GMT

G = GMT.peaks(); # Create one grid
D = grd2xyz(G); # Convert to x,y,z
gmtwrite(D, "lixo.xyz") # Save it as disk file
G2 = gmt("grdconvert lixo.xyz"); # Load it
imshow(G2) # and display

```

 ![GMTjl_tmp](https://global.discourse-cdn.com/julialang/original/3X/3/4/34f345650d09e7c5366d1b41557a5c74fa6d76f3.png)

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 9:00pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/8 "2022-05-24T21:00:02Z")

</div>

I’ve unlinked, removed GMT from my package environment, linked back, added the `GMT.jl` back in… same error. I’ve disabled the `PyCall`s via `conda` (I believe) I was making and removed it from my environment as well but nothing’s changed.  
I will say that if I evaluate `using GMT` a second time it won’t complain and will instantiate a `peaks()` grid but when I call `grd2xyz()` on it, then the same error happens again. I’m out of ideas but for a clean installation…

---

<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:** [May 24, 2022, 9:23pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/9 "2022-05-24T21:23:28Z")

</div>

> [@joa-quim](#):
>
> ~.julia/conda/3/lib/libgdal.30.dylib

It still seems to me that it is homebrew that has screwed (it does it many times). To check that try this on a shell (no Julia involved)

```julia
grdinfo @earth_relief_20m

```

you should see (or not, it it errors) the equivalent of

```julia
grdinfo @earth_relief_20m
c:/j/.gmt/server/earth/earth_relief/earth_relief_20m_p.grd: Title: SRTM15 Earth Relief at 20 arc minutes
c:/j/.gmt/server/earth/earth_relief/earth_relief_20m_p.grd: Command: grdfilter SRTM15_V2.4.nc -Fg37.1 -D1 -I20m -rp -Gearth/earth_relief/earth_relief_20m_p.grd=ns+s0.5+o0 --IO_NC4_DEFLATION_LEVEL=9 --IO_NC4_CHUNK_SIZE=4096 --PROJ_ELLIPSOID=Sphere
...

```

otherwise what I would try is to follow the leads of

```julia
otool -L ~.julia/conda/3/lib/libgdal.30.dylib

```

and/or those of the output of this shell cmd (if the shell command above didn’t error)

```julia
gmt --show-library

```

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 9:26pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/10 "2022-05-24T21:26:34Z")

</div>

A clean installation of `gmt` via homebrew and from `.julia/packages/GMT` has got me over that hurdle! I think maybe the problem was that I first added the julia wrapper and then `gmt` as such?

Anyways, I now get an `GMT error number = 79` when calling `gmt("grdconvert ~/Desktop/sample.xyz")`which I saw from your previous post that it has to do with `ghostscript` so will unlink and try again…

---

<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:** [May 24, 2022, 9:36pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/11 "2022-05-24T21:36:05Z")

</div>

> [@ctrebbau](#):
>
> A clean installation of `gmt` via homebrew and from `.julia/packages/GMT` has got me over that hurdle! I think maybe the problem was that I first added the julia wrapper and then `gmt` as such?

Yeap, that will end up with two GT installations and dependency hells are easy.

> [@ctrebbau](#):
>
> Anyways, I now get an `GMT error number = 79` when calling `gmt("grdconvert ~/Desktop/sample.xyz")`

What was the full error? That command does not produce any figure so `ghostscript` errors should not occur. But yes, if you ae using the `homebrew` install you’ll need to install `ghostscript` as well.

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 9:44pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/12 "2022-05-24T21:44:23Z")

</div>

My shell doesn’t know `grdinfo`.

`otool` output is `@rpath/libgdal.30.dylib (compatibility version 31.0.0, current version 31.2.0)`

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 9:45pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/13 "2022-05-24T21:45:58Z")

</div>

I did install `ghostscript` I think I had it installed previously by `LaTeX` or something, but I did re-run the brew command

---

<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:** [May 24, 2022, 9:46pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/14 "2022-05-24T21:46:05Z")

</div>

> [@ctrebbau](#):
>
> My shell doesn’t know `grdinfo` .

Sorry, my Windows habits. It should have been

```julia
gmt grdinfo ...

```

---

<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:** [May 24, 2022, 9:48pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/15 "2022-05-24T21:48:51Z")

</div>

> [@ctrebbau](#):
>
> `otool` output is `@rpath/libgdal.30.dylib (compatibility version 31.0.0, current version 31.2.0)`

`otool -L` prints lots of lines and the dependency conflicts use to be shown in one of those lines. As I said, this is debugging info that just tell us where the conflicts are comming from. Not how to solve them.

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 9:48pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/16 "2022-05-24T21:48:54Z")

</div>

> [@joa-quim](#):
>
> `gmt grdinfo `

I get no errors here!

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 9:51pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/17 "2022-05-24T21:51:07Z")

</div>

Oki, there were others but the first and closest match was the one I reported

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 24, 2022, 9:58pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/18 "2022-05-24T21:58:37Z")

</div>

So, here’s where I’m at:  
I load in data and packages -all good  
Then I use `CSV.write` to save a sample of my data to with an `xyz` extension  
Then when I call `G = gmt("grdconvert ~/Desktop/sample.xyz")` I get `ERROR 4: "~/Desktop/sample.xyz" not recognized as a supported file format. grdconvert (GMT_grdconvert): Not a supported grid format [~/Desktop/sample.xyz] ERROR: Something went wrong when calling the module. GMT error number = 79`

---

<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:** [May 24, 2022, 10:11pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/19 "2022-05-24T22:11:04Z")

</div>

Ok, maybe we can continue this on GMT.jl issue. No need to bother others with this issue.  
But the `ERROR 4: "~/Desktop/sample.xyz" not recognized as a supported file format.` is a GDAL error message and it means it could not deal with your `sample.xyz` file.

Does my synthetic example above (the one that ended with a figure) work for you?

EDIT: … or preferably on the GMT forum.

---

<div class="post-metadata">

**Author:** ![ctrebbau](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@ctrebbau](https://discourse.julialang.org/u/ctrebbau)\
**Post date:** [May 25, 2022, 3:39pm UTC](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596/20 "2022-05-25T15:39:48Z")

</div>

It is beautiful!

Sorry for not responding right away but since this is my first post the website disallowed further comments for 24 hours.

What should I do though? Is the workflow above correct, as far as it goes?

[Next page](https://discourse.julialang.org/t/heatmap-from-matrix-with-custom-indices/81596.md?page=2)
