Need help with my first contour plot on an Earth Relief based map (Julia GMT.jl)

My goal is to plot a map using the Earth Relief Grid data and then plot some filled contours in the ocean. Would anyone please help me figure out what I did wrong? My code can only produce a map. The contour did not plot at all. Many thanks!

Below is my code:

using GMT
using MAT

# plot the Earth Relief based map: 
grdimage("@earth_relief_10m", region=(180,320,10,80),
proj=(name=:lambertConic, center=[-105 35], parallels=[33 45]),
coast=(coast=true, water=:white), fmt=:jpg, show=true);

# Read data:
F1 = matopen("folder/test.mat");
A = read(F1, "A");

# Create the grid:
lon  = 20:0.25:379.75;
lat  = -90:0.25:89.75;
G2 = mat2grid(Array(transpose(A)), x=lon, y=lat);

# Create the colorbar
topo = makecpt(cmap=:jet, range=(0,10,0.02) ); 

# Plot the contour
grdimage!(G2, coast=true, color=topo,frame=(annot=45,grid=45,title="test"))

@Joaquim, I hope you do not mind tagging you on such posts? I certainly do not want you to feel pressured by my tagging. Many thanks for all of your help.

  • When you use show (or savefig) that is interpreted as closing/finishing the figure.
  • When you next use grdimage! you are appending on … an empty fig.
  • One normally do not append two grdimages without using some transparency or having a clip command in the middle. Otherwise second image completely hides the first.

PS. Don’t need to @tagg me, those post are meant to me.

1 Like

Many thanks, Joaquim!

I really want to keep the the Earth Relief data based map, so that one would have to be plotted using grdimage. In this case, what is the best way to solve my issue? I can plot the filled contour using a function other than grdimage?

I tried the below, but it is taking forever to execute:
contourf!(G2, topo, show=true)

Filled countours is a very heavy operation. You probably want to do a
also, contourf creats an image so it hides any previous image. I suggest that you look a bit at the GMT examples (including plain GMT figures) and understand better how it works.

Unfortunately, I got an error saying, “no method matching contour!”.

What is the best source for GMT.jl examples? Where can I find an example for such use cases, i.e., a grdimage based map plus a filled contour?

Many thanks.

p.s., it seems that GMT.jl has a steep learning curve. Hopefully, I’ll be more confident once I’m able to plot my first map successfully.

Have you looked at the GMT.jl examples that I indicated you before.

(and other gallery examples - which are often a bit complex examples)

julia> contour!
contour! (generic function with 5 methods)
1 Like

I’ll check them out! Many thanks for sharing :+1: