Is it possible to left justify annotations on the right (E) side of the plot?

I’m plotting a diagram in cartesian space, and because of a break in the Y-axis, and for general aesthetic reasons, I would like to be able to left-justify the annotations plotted on the right-hand-side (E) on the Y axis. See the attached image as an example: in this case, I think the plot would simply look nicer if the right side Y axis annotations were left-justified, even if that isn’t “correct” in the sense of aligning the values, but the values aren’t aligned anyway, because of the break in scale.

@pwessel @Joaquim

It seems the question is forgotten. I’m also curious if there is a solution to this. I tried to change FORMAT_FLOAT_MAP, but it doesn’t work as I expect.

gmt basemap -R0/10/0/1000 -JX10c/10c -BWSEN -Baf -pdf map --FORMAT_FLOAT_MAP='%-.12g'
1 Like

This isn’t the cleanest way, in that it would be nicer to use something like FORMAT_FLOAT_MAP, but it is possible to use plot custom axis labels using text, where the x-values should be constant and adjusted based on the x-axis scale:

gmt text -F+jML -N << EOF
-1 0 0
-1 10 10
-1 20 20
-1 30 30
EOF

We did not implement something like that because we (subjectively, I know) felt it would look ugly. We spend much effort figuring out the base alignment, sometimes via PostScript math inside the plots, to arrive at what we show, and those strings are right-justified for that axes. Introducing left justification means more programming for a very unlikely situation - so perhaps the custom annotation scheme is not so bad. I am certainly not highly motivated to look at this in detail give all the other tasks on my plate.

Thank you all for your comments and suggestions.

Indeed I thought about using pstext (sorry I’m still an old-school GMT’er), and seeing as how this is probably the only solution available at the moment, I will use that. It is easy enough to implement, as there are not that many labels to plot and they can be generated automatically in the shell script.

Cheers, Jed

Is there any chance this possibility is added? Thanks.

Not really sure what to answer. First thing to do is to turn it into a Feature Request. But than, I feel like in Paul’s answer. Given our current resources, it would help quite a bit if someone does the first steps in, for example, identifying the code sections that determine the current behavior (that actually looks buggy to me since justification in this example is neither left or right) and do some attempts. I could than provide more assistance.

I don’t know what to answer either. I don’t really understand why left-justification for the axis annotations need to be so hard internally while the gmt text -F+jML -N approach mentioned by @maxrjones seems super easy and appears to work well (except one needs to create the labels manually, same way as gmt does internally). But I am not a gmt developer. I could try but I don’t know where I should start looking for in the code.

Regarding the aesthetics left-justified Y axis annotations on the right side of the plot have been a default in gnuplot for example. I think in matplotlib too.

Surely, there are likely situations i haven’t thought about, like perspective views at various angles etc. But gmt text ... appears so deceitfully simple.

One thing that occurs immediately to me is that for a right justification one needs to know the maximum length of the annotations an offset the insert point by it. Things seem that should be simpler for the left justification.

Computing string length is bloody tricky (different characters have different widths). Paul used to do it with PostScript programming.

A possible trick that came to my mind is if we could pad the strings with invisible characters. That way, right and left justification would became the same (all words would have the same length).

I don’t really understand the meaning of the above.

What I understand very well is the code below, 6p offset is a gmt default for the primary axis annotations, and the result. I added a 60 degree rotation just to check how it’s gonna look.

gmt begin gmt-text-annotations png

  gmt basemap -R0/1000/0/1000 -JX5c -Bwsne -Bpy500f -Bpx500f -p60
#Y annots on the right
  gmt text -F+jML -Dj6p/0 -N -p << EOF
1000 0 0
1000 500 500
1000 1000 1000
EOF
#Y annots on the reft
  gmt text -F+jMR -Dj6p/0 -N -p << EOF
0 0 0
0 500 500
0 1000 1000
EOF
#X annots at the bottom side
  gmt text -F+jTC -Dj0/6p -N -p << EOF
0 0 0
500 0 500
1000 0 1000
EOF
#X annots at the top of the plot
  gmt text -F+jBC -Dj0/6p -N -p << EOF
0 1000 0
500 1000 500
1000 1000 1000
EOF

gmt end show

The result:

With this I mean that for a non-developer user like me all possible issues of label placement and alignment have already been solved in gmt text. One just needs to call it providing the right annotations at right intervals as the input.