Error in colorbar position with Julia?

I am beginning with Julia so I am not very sure if I am doing something wrong. I try to reproduce the Color Image example.

In the original image, the colorbar is on top of the map. I got it within the map.

(I reduce its quality to upload it here).

Full script run in Pluto Notebook.

begin
	using GMT
	topo = makecpt(color=:rainbow, range=(1000,5000,500), continuous=true);
	grdimage("@tut_relief.nc", shade=(azimuth=100, norm="e0.8"), proj=:Mercator, frame=:a, color=topo)
	colorbar!(pos=(anchor=:TC,length=(12.5,0.6), horizontal=true, offset=(0,1.0)),
	          color=topo, frame=(ylabel=:m,), fmt=:jpg, show=true)
end

I’ll try to look at this later but in very quick try I even got a strange error

colorbar!(pos=(anchor=:TC,length=(12.5,0.6), horizontal=true, offset=(0,1.0)), color=topo, frame=(ylabel=:m,), show=true)
psscale [ERROR]: North is outside -90 to +90 degree range
psscale [ERROR]: General map projection error
ERROR: Something went wrong when calling the module. GMT error number = 74

however, this more concentrated form works

topo = makecpt(color=:rainbow, range=(1000,5000,500), continuous=true);
imshow("@tut_relief.nc", shade=(azimuth=100, norm="e0.8"), proj=:Mercator, frame=:a, color=topo, colorbar=(pos=(anchor=:BC,length=(12.5,0.6), horizontal=true, offset=(0,1.0)), ylabel=:m))

Ah, and this also works

grdimage("@tut_relief.nc", shade=(azimuth=100, norm="e0.8"), proj=:Mercator, frame=:a, color=topo)

colorbar!(pos=(anchor=:BC,length=(12.5,0.6), horizontal=true, offset=(0,1.0)), color=topo, ylabel=:m, show=true)

I dropped the fmt=:jpg because it really brings nothing when one do not specify also the figure name.

Don’t understand how you got your example map. Either with Julia or plain GMT CLI I get the colorbar inside but on the top side.

One thing very useful to know about the Julia wrapper is that the option Vd=1 in any command prints the corresponding GMT command. So, using it I reproduced the bellow CLI commands that renders the same figure as the Julia ones.

julia> gmtwrite("topo.cpt", topo)

gmt grdimage @tut_relief.nc  -JM14c -Ba -n+a -Ctopo.cpt -I+a100+ne0.8 -P -K > lixo.ps
gmt psscale  -R -J -Baf -By+lm -BWSen -DJTC+w12.5/0.6+h -Ctopo.cpt -K -O >> lixo.ps

Joaquim, How exactly do you work with Julia? Do you write directly on the terminal? Use a file?

I managed to get the figure. I saw that I got this message:
From worker 4: psscale [ERROR]: Found no history for option -R

So I add region="@tut_relief.nc" in my code within grdimage.

begin
	topo2 = makecpt(color=:rainbow, range=(1000,5000,500), continuous=true);
	grdimage("@tut_relief.nc", shade=(azimuth=100, norm="e0.8"), proj=:Mercator, frame=:a, color=topo2, region="@tut_relief.nc")
	colorbar!(pos=(anchor=:TC,length=(12.5,0.6), horizontal=true, offset=(0,1.0)),
	color=topo2, frame=(ylabel=:m,), fmt=:jpg, show=true)
end

Hmm, don’t know what Pluto is doing here. I don’t like that Pluto obliges to put multi-commands inside a begin/end block so I never used that. I either put one command per cell or use the alternative package Neptune that does not have this constrain and is not reactive.

I always use the REPL or scripts in VSCode and Neptune or Jupyter for notebooks.

Thanks Joaquim.

I try the original script on Neptune and it works fine. So there is a problem with Pluto.

The thing that occurs to me is it runs those two commands in parallel and hence in different sessions, so common options are not visible to each other.