geofan
March 31, 2023, 10:35pm
1
I’ve tried to plot the degree symbol in a text field using the following two lines:
fig.text(text=str(inc) + "u"8\u00b0"", x = text_long, y = text_lat, angle = tilt)
and
fig.text(text=str(inc) + chr(176), x = text_long, y = text_lat, angle = tilt)
Neither renders the symbol properly, which shows up as such:
Anybody have any idea if there’s a way to resolve this and properly plot a degree symbol in figure text?
wsja
March 31, 2023, 11:02pm
2
I’ve got the same problem. I tried u"\N{DEGREE SIGN}" as well as octal codes for different encodings, but did not get it to work. Might be a bug in PyGMT?
Hello @geofan ,
your issue is probably related to Better support of non-ASCII characters in PyGMT arguments · Issue #2204 · GenericMappingTools/pygmt (github.com) .
Beside using the corresponding octal code (\260, please not the addional \ in the code example below), you can plot the degree symbol in GMT / PyGMT using @.
Code example :
import pygmt
fig = pygmt.Figure()
fig.basemap(
region=[-1, 1, -1, 1],
projection="X2c",
frame="a1f0.5g1",
)
fig.text(
text="42\\260", # using octal code, please not the addional "\"
# text="42@.",
x=0,
y=0,
)
fig.show()
#fig.savefig(fname="degree_sign_gmt.png")
Output figure :
geofan
April 3, 2023, 6:11pm
4
Thanks Yvonne, that worked like a charm!