About coding efficiency: modern mode, begin , figure and subplot

Hi there,

I recently switched to modern mode, and I’d like to open a discussion on how to improve coding efficiency and readability.

For example, I found the way subplot handles figure’s dimension very confusing. The feature is nice but it is complicated to get it right.

Modern mode

First about the formalism. True it is flexible, but IMO the documentation is short on explanations and motivations behind all the possibilities :

### Single plot simple
gmt [...]

### Single plot simple V2 : in gmt session
gmt begin (name) (format)
gmt end

### Single plot V3 : can extend to multiple figures in same gmt-session
gmt begin 
gmt figure (name) (format)
[...] no "begin" / no "end" ?
gmt end

### Subplot cleaner
gmt begin
gmt figure
gmt begin subplot -Ff / -Fs (...)
gmt subplot set
[...] no "begin" / no "end"
gmt subplot end
gmt end 

### Subplot dirtier
gmt begin
gmt figure
gmt begin subplot -Ff / -Fs (...)
[...] -c(row,col)
gmt subplot end
gmt end 

As you can see, all roads lead to … confusion if you’re starting without a map (see what I did there? :slight_smile: ).

Well, I guess each individual has some sort of habits when it comes to code… or pretty much anything, but while it’s not forbidden to drive on the left lane, a clear traffic regulation would help (see? I did it again … ok I stop with this lame spinning metaphor :wink: ).

GMT session

The way it works is pretty straightforward and clearly it has been thought for efficiency and plethora of information can be found in the documentation. Still, what’s going on with makecpt and -C option ?
Am I the only one to just always use :

gmt makecpt [...] -H > mycpt.cpt

Why sometimes grdimage doesn’t require it ? Can we do like in fortran : IMPLICITE_NONE ? (I might have lost some people here, I’m sorry).

My point is, back to the habits, it’s difficult to become efficient when rules change all the time.


Subplot and figure dimensions, my nemesis. It is actually an experience from last week (as well as this discussion about subplot frame on github that motivated me to rant here).

To cut it short, I plotted 3 figures (x 6 subfigures) in the same gmt-session. Very compact, the advertisement didn’t lie.

I used subplot -Fs, my laptop was making noise like a 747 and everything was fine
The problem was some labels on the colorbar. If the text was long, the subplot on the right hand side would make the whole figure wider. Inconsistency + OCD = rant.

So I tried subplot -Ff and let gmt handle the subplot size (maybe related to a reported bug? I don’t know).
But all of a sudden the coast and grdimage had unexplained offsets. I was tired and just resorted to go back to -Fs and remove the labels.

Finally, the frame. IMPLICIT_NONE. The intertwining of -B options and labels is magical when everything’s fine, but can be frustrating when it’s not (at least in subplot environnement).

Do people have problem with overlapping frames, redundant automatic annotations (or even plot shift like my -Ff above) ?


What can be done to improve and/or promote efficiency, readability and develop a code of good practice ?

G. out :microphone:

Thanks for your comments on modern mode. Apart from the always-true “the documentation could be better” (and we are working on that, plus awaiting a NASA proposal decision that would really help with that), here are a few comments:

  • There are hundreds of programming languages out there because as soon as one is invented, others see implementation details they would have done differently. Nothing wrong with that, and your comments regarding how we chose to do things are similar. Yes, other implementations would have been possible, but this is what we did after a considerable amount of deliberations. We are not going to rewrite the high-level view of it.
  • We designed modern mode to be simple. That made putting some limitations on what can be done. Not every thing one can script in classic mode may ahve a path to modern mode. It is a trade-off in simplicity versus functionality.
  • The gmt figure command is a switch that sets the current output focus to the named figure. You can go back and forth between several figures in a session is that simplifies the workflow. Hence there is no begin/end required or expected.
  • Likewise, gmt subplot set is another switch that sets the focus of plotting to the specified panel. It stays there until changed or the subplot ends. In an alternate universe, one could imagine a gmt panel begin|end module that would address your begin|end idea, but we chose to do the switch approach here.
  • The subplot command still has many limitations. It is not yet possible to vary the number of panels per row, for instance (this will require nested subplots), and users wanting to override the automatic settings will run into problems. Also, unlike most of GMT, subplot is very recent (as is all of modern mode) and hence it is expected to have more bugs and failures than the rest of GMT.
  • Regarding redundant automatic annotations: This is what -SC and -SR set out to solve. If you dont use those then you are on your own regarding using the -B settings on individual panels or for the entire subset. The test suite for subplot has many simple examples testing these things.
  • The best way to help find and fix problems is to isolate one problem in as small an example as possible so that we can use that as a failing test script and work to fix the problem. Giving examples with lots of concurrent issues make it much harder to solve, obviously. I think the GMT team has a very good record of being responsive to bug reports and issue fixes as fast as humanly possible.

I couldn’t agree more.
My intention with this thread was not to criticize the way things are implemented, but rather discuss / improve coding efficiency for people starting GMT (and the more experienced alike)… Get the good habits, such as, “where is it best to put the frame annotations” or “how to avoid too much text in a subplot” (so on and so forth).
Since I’ve switched to modern mode, and especially since I’ve used batch (or movie), my implementation has improved, but with subplot I can get things right without many trials and errors.

I guess to clarify my point, would it be sensible to create a “tutorial” section more focused on how to articulate things (similar to the hints you left for some modules)?