Issue with quoted lines - Labels at the end of the line overlapping line [PyGMT]

Hello,

I’m encountering an issue with quoted lines in PyGMT while trying to plot lines with labels. Specifically, I want the labels to always appear at the end of the line, so I using the style: “qN+1:+ltext”. However, the problem is that the label is overlapping the line, and I want the label to start right where the line ends. As I increase the font size, the label overlaps the line even more.

I have provided a code example below to illustrate the problem:

import numpy as np

import pygmt

# Generate a two-point line for plotting

x = np.array([2, 4])

y = np.array([5, 5])

fig = pygmt.Figure()

fig.basemap(region=[0, 6, 3, 6], projection="X15c/15c", frame="wsne")

fig.plot(x=x, y=y, pen="2.25p", style="qN+1:+ltext+f15p+p1p")

y -= 1

fig.plot(x=x, y=y, pen="2.25p", style="qN+1:+ltext+f25p+p1p")

fig.show()

The resulting figure shows the label overlapping the line

Is there any way to address this issue? I’ve checked the GMT documentation (plot — GMT 6.4.0 documentation), but couldn’t find a solution. Any help or suggestions would be greatly appreciated. Thank you!

Robson

Well, that’s why they are called “annotated lines” and not “lines next to annotations”, no?

Maybe have a look at the +n (nudge) modifier?

I was expecting a solution like this, but it seems that the nudge modifier (+n) is ignored when using qN+1. It appears that the quoted line will not provide the expected result since I cannot apply an offset to the annotation to remove it from above the plotted line.

Perhaps +jLM is what you need?

Is it a legend that you are trying to create?

It also doesn’t work; the documentation says the following:

+jjust
Set label justification [Default is MC]. Ignored when -SqN|n+|-1 is used.

No, I want to plot trajectories, and at the end of each trajectory, I want to insert a label with the distance of each trajectory. That’s why it’s important that the label doesn’t overlap with the line, so that the end of the trajectory isn’t covered. I thought there might be a way to add some offset to the label, but the +n (nudge) modifier doesn’t work when -SqN|n+|-1 is used, nor does +jLM. It’s a pity because in this case, the modifiers would be very useful.

Suggest you post a feature request on our GitHub page; otherwise things get lost.

We have an example similar to what you want. Have a look at that fig and script

Thanks, I followed the example and it looks like I got what I was expecting:

import numpy as np

import pygmt

# Generate a two-point line for plotting

x_track = np.array([0, 2, 3, 3.5, 5])

y_track = np.array([2, 3, 4, 4, 5])

# Calculate the angle

angle_1 = np.degrees(np.arctan2(x_track[-1] - x_track[-2], y_track[-1] - y_track[-2]))

fig = pygmt.Figure()

fig.basemap(region=[0, 6, 3, 6], projection="X15c/15c", frame="wsne")

fig.plot(x=x_track, y=y_track, pen="2.25p,red")

fig.text(x=x_track[-1], y=y_track[-1], text='Text', justify='ML', angle=angle_1, offset='J0.4c', font='14p', pen='1p')

fig.show()