Mutual exclusivity of `imshow` and `inset` in current API

It appears that the current API of GMT.jl allows complex plots using either imshow or inset, but not both. In classic mode (I guess that is what it is called?) there is no imshow! function:

help?> imshow!
search: imshow

Couldn't find imshow!
Perhaps you meant imshow, ispow2, @show, show or image!
  No documentation found.

  Binding imshow! does not exist.

On the other hand, in modern mode inset doesn’t work:

function inset_modern()
    try
        gmtbegin("test_insets.pdf")
        coast(
            proj = :Mercator,
            region = (110, 210, -40, 40),
            figsize = 15,
            frame = :auto,
            land = :dimgray,
            shore = :thinner,
        )
        basemap(
            frame = (; grid = :auto),  # Without this there is a second error.
            inset = (; anchor = :BL, width = 3.8, offset = (10.9, 6)),
            box = (; fill = :white, pen = 1, clearance = 0.1, shaded = true),
        )
        coast(
            region = :global,
            proj = (; name = :ortho, center = (120, 0), parallel = 3.8),
            frame = (; grid = :auto),
            land = :brown,
            area = 5000,
            DCW = (; country = "AU", fill = :bisque),
            xshift = 10.9,
            yshift = 6,
        )
        gmtend()
    catch e
        gmtend()
        throw(e)
    end
end
julia> inset_modern()
basemap [ERROR]: Option -F is only allowed with -L and -T
ERROR: Something went wrong when calling the module. GMT error number = 72
Stacktrace:
 [1] inset_modern()
   @ Main ~/hazcode/GMT/julia_GMT/test_insets.jl:73
 [2] top-level scope
   @ REPL[6]:1

caused by: Something went wrong when calling the module. GMT error number = 72
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] gmt(cmd::String, args::Nothing)
   @ GMT ~/vcs/GMT.jl/src/gmt_main.jl:284
 [3] finish_PS_module(d::Dict{Symbol, Any}, cmd::Vector{String}, opt_extra::String, K::Bool, O::Bool, finish::Bool, args::Nothing)
   @ GMT ~/vcs/GMT.jl/src/common_options.jl:3407
 [4] basemap(cmd0::String, arg1::Nothing; first::Bool, kwargs::Base.Iterators.Pairs{Symbol, NamedTuple, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:frame, :inset, :box), Tuple{NamedTuple{(:grid,), Tuple{Symbol}}, NamedTuple{(:anchor, :width, :offset), Tuple{Symbol, Float64, Tuple{Float64, Int64}}}, NamedTuple{(:fill, :pen, :clearance, :shaded), Tuple{Symbol, Int64, Float64, Bool}}}}})
   @ GMT ~/vcs/GMT.jl/src/psbasemap.jl:67
 [5] inset_modern()
   @ Main ~/hazcode/GMT/julia_GMT/test_insets.jl:55
 [6] top-level scope
   @ REPL[6]:1

The working version of the above function using classic mode:

function inset_classic()
    coast(
        region = (110, 170, -44, -9),
        proj = :Mercator,
        figsize = 15,
        shore = :thinner,
        land = :brown,
        water = :azure1,
    )
    basemap!(
        inset = (;
            anchor = :BL,
            width = 3.8,
            offset = (10.9, 6),
        ),
        box = (;
            fill = :white,
            pen = 1,
            clearance = 0.1,
            shaded = true,
        ),
    )
    coast!(
        region = :global,
        proj = (; name = :ortho, center = (120, 0), parallel = 3.8),
        frame = (; grid = :auto),
        land = :brown,
        area = 5000,
        DCW = (; country = "AU", fill = :bisque),
        xshift = 10.9,
        yshift = 6,
    )
end

Now, the actual plot I am trying to make has multiple layers:

  • coast
  • grdimage + grdcontour + colorbar
  • imshow (using an GMTDataSet, so image! is not a substitute I think)
  • arrows + scatter + legend
  • basemap (inset) + coast + scatter

Is there a way to have both imshow and inset layers, that I am missing?

Cheers,
Leon

The imshow (not imshow!) is a convenient function that is not part of GMT ans is meant mainly to be used as a one-liner

help?> imshow
search: imshow

  imshow(arg1; kw...)

  Is a simple front end to the grdimage grdview programs that accepts GMTgrid, GMTimage, 2D array of floats or strings with file names of
  grids or images. The normal options of the grdimage and grdview programs also apply here but some clever guessing of suitable necessary
  parameters is done if they are not provided. Contrary to other image producing modules the `show` keyword is not necessary to display the
  image. Here it is set by default. If user wants to use imshow to create layers of a more complex fig he can use show=false for the
  intermediate layers.

Now, inset is an option in the basemap classic mode but it’s a standalone module (easier to use) in modern mode. So your first function, inset_modern() cannot use the inset option but has to call the inset module.

If you want to make a multiple layers plot it’s better not to use imshow, though in principle you should be able to do (or expand the contour, coast options)

  • imshow(G, contour=true, colorbar=true, coast=true, show=false)
  • arrows!(…)
  • basemap!(inset)

That makes sense, thanks.