Using superscript/subscript for axis labels?

I keep running into an error when trying to use superscript for axis labels. From my reading of the GMT docs, it seems like this should work in pygmt:

fig.colorbar(frame=[‘af’, ‘x+l"Long-term 95@+th@+ percentile NDVI"’])

However, this keeps kicking an error. For reference, other @ options:

fig.colorbar(frame=[‘af’, ‘x+l"Long-term 95@-th@- percentile NDVI"’])

work fine – so it is something to do with the handling of the ‘+’ in that argument. Any ideas for a workaround?

I think the workaround is to use text for the colorbar label:

fig = pygmt.Figure()
fig.grdimage(grid=grid, projection="R12c", cmap="bamako")
fig.colorbar(frame=["af"])
fig.text(text="Long-term 95@+th@+ percentile NDVI",position="CB",offset="0c/-1.8c",font="13p,Helvetica,black", no_clip=True)
fig.show()

where you could adjust position if your colorbar is not center-bottom and/or the dx/dy offset to get the positioning correct.

My understanding is that the @+ macro cannot be supported in arguments to frame/-B in PyGMT/GMT due to the way that modifiers are parsed, so that is only an option in text. But, other functions that parse -B can support LaTeX expressions (https://docs.generic-mapping-tools.org/dev/cookbook/gmt-latex.html), which would allow superscripts. So, that could be a feature request if it would be helpful for cases such as this.

Thanks for this workaround! I dug around in base GMT and looked into latex support, but I guess it isn’t in pygmt yet – both of these:

fig.colorbar(frame=['af', 'x+l"Long-term 95<math>^{th}</math> percentile NDVI"'])
fig.colorbar(frame=['af', 'x+l"Long-term 95@[^{th}@[ percentile NDVI"'])

won’t work either. I’ll open a feature request!

Thanks again for the help!