# ANN: New GMT interface

**URL:** https://discourse.julialang.org/t/ann-new-gmt-interface/6946
**Category:** General Usage
**Tags:** plotting, gmt
**Created:** [November 7, 2017, 10:47pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946 "2017-11-07T22:47:16Z")
**Posts on this page:** 20
**Page:** 1

<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: [November 7, 2017, 10:47pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/1 "2017-11-07T22:47:16Z")

</div>

Hi,

[GMT.jl](https://github.com/GenericMappingTools/GMT.jl) got a new tag (0.2) that introduces a new higher-lever type of interface to the GMT package.

While this new interface makes it more similar to Plots.jl calls, and indeed there is some overlap, I would like to recall that GMT.jl ads a geographically dimension to your plots.

Contributions, specially regarding on how to create a better documentation without repeating the original GMT docs, are welcome.

---

<div class="post-metadata">

### Author: ![crbinz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crbinz/32/1919_2.png) [@crbinz](https://discourse.julialang.org/u/crbinz)
#### Post date: [November 8, 2017, 4:44am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/2 "2017-11-08T04:44:40Z")

</div>

Great! This package has always interested me, but the old syntax scared me. I’ll be checking it out more closely, now.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [November 8, 2017, 8:24am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/3 "2017-11-08T08:24:02Z")

</div>

Naive question: why not separate the backend (manipulating geographic and Cartesian data sets) from the plotting frontend, add some nice plot recipes and let the actual plotting be handled by `Plots.jl` (or `Makie.jl`)? Won’t that make your life easier?  
Sorry if I overstepped…

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [November 8, 2017, 10:24am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/4 "2017-11-08T10:24:10Z")

</div>

The idea to split plotting into dedicated tasks/libraries e.g. coordinate transformation is not a new one…  
Keep in mind, that GMT is a big-block of SW and written in C. Splitting out something there is not straight forward.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [November 8, 2017, 10:31am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/5 "2017-11-08T10:31:52Z")

</div>

Sorry, so the plotting is intertwined with the “backend” calculations and therefore it’s hard to separate the two?

---

<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: [November 8, 2017, 12:35pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/6 "2017-11-08T12:35:00Z")

</div>

GMT is essentially made of two small libraries (total ~ 4 Mb) and a driver executable (the gmt.exe). The Julia wrapper replicates this command line driver functionality and, in a single shot, gives access to whole GMT. The compact syntax that scares some people is needed given the large level of details one may control combined with a large number of options a module can perform.

The new upper level off access hides away some of this complexity and could in principle be added as a Plots backend but this would be a large work (I can’t even say I understand the Plots code) and furthermore I’m not even convinced I liked the Plots syntax very much with its arguments at times symbols, other numbers and other text strings, sorry.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [November 8, 2017, 12:37pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/7 "2017-11-08T12:37:28Z")

</div>

I see, cool. Thanks for the clarification 👍

---

<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: [November 8, 2017, 12:40pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/8 "2017-11-08T12:40:58Z")

</div>

GMT is mostly known for its graphics/images quality but it actually is a very powerful data processing tool too and this two features are intimately connected so the notion of splitting them sounds a bit weird to me.

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [November 8, 2017, 6:15pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/9 "2017-11-08T18:15:15Z")

</div>

I have to apologize, i was a little bit confused as i was in a parallel discussion about plotting…

For me split means: make internal processing steps of GMT available in the GMT.jl adaptation to use it in other plotting.

---

<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: [November 8, 2017, 6:40pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/10 "2017-11-08T18:40:08Z")

</div>

> make internal processing steps of GMT available in the GMT.jl adaptation to use it in other plotting.

But you can. GMT communicates in-out via its [data types](https://genericmappingtools.github.io/GMT.jl/latest/types/) that can simply be accessed by other codes. In particular, there is a large potential of cooperation with Images.jl that could benefit enormously from the GMT capacity to read all sort of images formats (which it does via GDAL).

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 9, 2017, 6:13am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/11 "2017-11-09T06:13:50Z")

</div>

Wow! These examples look great! Thank you for your work, I will definitely give it a try.

I always wanted to be able to plot the results of spatial estimation problems in my GeoStats.jl package on spherical coordinates like in your first example. Suppose I have a 2D Julia array A with values A[i,j] and coordinates in degress lon[i], lat[j], how would you plot the array of values A as a heatmap on the globe?

Reading the docs now…

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 9, 2017, 6:17am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/12 "2017-11-09T06:17:33Z")

</div>

I would also love to see some sort of integration with Plots.jl and PlotRecipes.jl specially. Ideally I could define recipes to plot on the globe without depending on GMT.jl.

---

<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: [November 9, 2017, 2:02pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/13 "2017-11-09T14:02:45Z")

</div>

If your 2D array `A` is already on a regular grid the best thing would be to wrap in a [GMTgrid](https://genericmappingtools.github.io/GMT.jl/latest/types/#Grid-type-1) type and than use it in `imshow` ord `grdimage`. `imshow` is currently just an alias+some\_guessings of `grdimage` but the idea is to extend it to also deal with the 3D `grdview`. If `A` is not a regular grid you create one with `surface` like in the [contours](https://genericmappingtools.github.io/GMT.jl/latest/examples/#Simple-contours-1) example. Remember that elaborate GMT plots are made with the `layer cake` model where you keep adding new layers, likely from different modules, to your plot and at the end display it.

---

<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: [November 9, 2017, 2:04pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/14 "2017-11-09T14:04:13Z")

</div>

You cannot NOT depend on GMT.jl because it’s the working beast that knows how to communicate with the GMT library.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 9, 2017, 5:14pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/15 "2017-11-09T17:14:23Z")

</div>

@joa-quim can you maybe share a minimum working example with the 2D Julia array I mentioned?

---

<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: [November 9, 2017, 6:53pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/16 "2017-11-09T18:53:01Z")

</div>

OK, a fake example that should give you a Mercator map of Gulf of Angola random colorized ocean displayed from PostScript

```julia
x = collect(linspace(0,20,256)); # Longitude vector between 0 and 20 degree East
y = collect(linspace(0,20,256)); # Latitude vector between 0 and 20 degree North
A = rand(Float32, 256, 256); # Your A array (note the dimensions nx x ny)

G = GMT.GMTgrid("", "", [minimum(x), maximum(x), minimum(y), maximum(y), minimum(A), maximum(A)], [x[2]-x[1], y[2]-y[1]], 
	            0, NaN, "", "", "", "", x, y, A, "x", "y", "z", "");

grdimage(G, proj="M10c", frame="a") # This will use the default color scale
coast!(region=[0 20 0 20], land="brown", show=true) # Pay attention to use 'coast!' and not 'coast' because we are appending to an existing plot

```

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 10, 2017, 3:05am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/17 "2017-11-10T03:05:46Z")

</div>

This is what I get when I run the code:

 ![Screenshot from 2017-11-09 19-04-16](https://global.discourse-cdn.com/julialang/original/3X/0/5/05359435040025db033c3886d09593022459af19.png)

Does it look correct?

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 10, 2017, 3:11am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/18 "2017-11-10T03:11:09Z")

</div>

Nevermind, I fixed the example to something more intuitive.

I need to read the docs to get something out of GMT, it is not easy to catch up the syntax. It would be great to have a set of working examples discussing the features.

---

<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: [November 10, 2017, 2:44pm UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/19 "2017-11-10T14:44:59Z")

</div>

Well, everybody has to read the docs. Either for learning or for advanced usage. I’m a GMT developer and have to read the docs all the time for non trivial things. GMT is just too big for anyone to know it by hart.

People complain about the syntax but let me explore a bit just the `frame="a"` option above. It means draw axes with automatic labeling. Now, if we want we can control the label font, the label font size the spacing from the labeling from the axes, the tick marks length, which axes to plot, which axes to annotate and more. So, for example if one want to plot all 4 axes but annotate only the left and bottom, one would use `frame="a WSen"`. But for plotting only the left axes (the West) it would be `frame="a W"`. And this still by letting the automatic labeling decide what to do for us. Imagine what it would take to spell all this options. Just for the `WSen` one would have to do something like.

`annotate_west=true, annotate_south=true, draw_only_east=true, draw_only_north=true`

expand this to other options and it would take a page just to fine control a simple plot. This is the challenge of creating an upper level interface. The other challenge is on how to document it. I can’t just duplicate all the GMT documentation in GMT.jl. So far what I came out with was to put a link after each option directing to the GMT corresponding documentation, See for [example the coast](https://genericmappingtools.github.io/GMT.jl/latest/#GMT.coast) module. But, as mentioned in the opening post of this thread, I most than welcome suggestions on how to improve both the package and its docs.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [November 11, 2017, 3:11am UTC](https://discourse.julialang.org/t/ann-new-gmt-interface/6946/20 "2017-11-11T03:11:10Z")

</div>

@joa-quim thanks for sharing the full reference, it is helpful.

I have a suggestion for you. Try to concentrate your efforts on writing your own tutorials with GMT.jl for common tasks people always ask you. Tutorials are much more effective and helpful than tons of text with formal specifications or a hand of disconnected examples. Specially when it comes to a plotting package (no one has time to learn the internals of complex transformations producing the graphics on the display).
