GMT: add lines to a map

After plotting a map region with coast, I’d like to add a series of lines. I’m unable to correctly specify the arguments for the lines! call. I’ve also tried giving the x and y as separate [long] and [lat] vectors to lines. Error thrown is shown in the expandable section below.

using GMT
function main()
    coast(region=[-116 -71 39 49],                                   
              proj=(name=:Albers, center=[-96 39], parallels=[40 50]), 
              frame=:none,         
              resolution=:high,    
              area=250,           
              land="#2FD63E",       
              shore=:thinnest,    
              borders=((type=1, pen=:thin), (type=2, pen=:thinnest)),
              title="",
              show=true)

    positions = mat2ds([-72 41
                        -114  46])
    lines!(positions,
        pen = (0.75, "#E71F1E"), show = true)
end
Error
julia> main()
Error: /undefined in A
Operand stack:
   0
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1974   1   3   %oparray_pop   1973   1   3   %oparray_pop   1961   1   3   %oparray_pop   1817   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:767/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
Current file position is 175302
psconvert [ERROR]: System call ['/Users/foouser/.julia/artifacts/0d9e7c35bc21411c7d9c194f790e30a95a4a5795/bin/gs' -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/var/folders/zf/rr083cw10cv4zl468c6lt5gm0000gn/T/GMTjl_foouser.ps' 2> './psconvert_49997c.bb'] returned error 256.
ERROR: Something went wrong when calling the module. GMT error number = 79
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] gmt(::String)
    @ GMT ~/.julia/packages/GMT/r3nfS/src/gmt_main.jl:169
  [3] showfig(d::Dict{Symbol, Any}, fname_ps::String, fname_ext::String, opt_T::String, K::Bool, fname::String)
    @ GMT ~/.julia/packages/GMT/r3nfS/src/common_options.jl:4233
  [4] finish_PS_module_barr_last(d::Dict{Symbol, Any}, cmd::Vector{String}, fname::String, fname_ext::String, opt_extra::String, output::String, opt_T::String, K::Bool, P::Nothing)
    @ GMT ~/.julia/packages/GMT/r3nfS/src/common_options.jl:4581
  [5] finish_PS_module(::Dict{Symbol, Any}, ::Vector{String}, ::String, ::Bool, ::Bool, ::Bool, ::GMT.GMTdataset{Float64, 2}, ::Vararg{Any})
    @ GMT ~/.julia/packages/GMT/r3nfS/src/common_options.jl:4519
  [6] _common_plot_xyz(cmd0::String, arg1::GMT.GMTdataset{Float64, 2}, caller::String, O::Bool, K::Bool, is3D::Bool, d::Dict{Symbol, Any})
    @ GMT ~/.julia/packages/GMT/r3nfS/src/psxy.jl:361
  [7] #common_plot_xyz#858
    @ ~/.julia/packages/GMT/r3nfS/src/psxy.jl:13 [inlined]
  [8] lines(cmd0::String, arg1::Matrix{Float64}; first::Bool, kwargs::@Kwargs{pen::Tuple{Float64, String}, show::Bool})
    @ GMT ~/.julia/packages/GMT/r3nfS/src/plot.jl:615
  [9] lines!(arg1::Vector{Float64}, arg2::Vector{Float64}; kw::@Kwargs{pen::Tuple{Float64, String}, show::Bool})
    @ GMT ~/.julia/packages/GMT/r3nfS/src/plot.jl:630
 [10] lines!
    @ ~/.julia/packages/GMT/r3nfS/src/plot.jl:630 [inlined]
 [11] main()
    @ cardmap /Volumes/personal/2024_thomas_newsletter/cardmap/src/cardmap.jl:24
 [12] top-level scope
    @ REPL[6]:1

julia> versioninfo()
Julia Version 1.10.7
Commit 4976d05258 (2024-11-26 15:57 UTC)
Build Info:

    Note: This is an unofficial build, please report bugs to the project
    responsible for this build and not to the Julia project unless you can
    reproduce the issue using official builds available at https://julialang.org/downloads

Platform Info:
  OS: macOS (arm64-apple-darwin23.6.0)
  CPU: 16 × Apple M3 Max
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)
Environment:
  JULIA_EDITOR = hx
  JULIA_PKG_DEVDIR = /Volumes/work/julia/dev

When you used ‘show’ in the ‘coast’ command you finished the PostScript file. Don’t do that. The ‘show’ option is used only in the last command.

3 Likes

Thank you!