Superscription and subscription in legend and colorbar in pygmt

Hello all,

I am using pygmt to generate some mapes. When I try to insert a legend or colorbar frame into the map with some superscriptions/subscriptions, it always shows the Error:

“latex is not installed or not in your executable path - cannot process LaTeX to DVI.”
“gmt_map_text: Conversion of LaTeX to EPS failed”.

After I installed MikTex, the Error becomes into the following:

“colorbar [ERROR]: gmtplot_latex_eps: Unable to load EPS file equation.eps”
“colorbar [ERROR]: gmt_map_text: Conversion of LaTeX to EPS failed”

I am using Windows 10, Anaconda 22.9.0, pygmt v0.7.0, GMT 6.4.0.

Can anyone help me with this?

Thanks!

Hello @Y-Tang99,

thanks for trying out PyGMT!

Instead of invoking LaTex you can accomplish text with subscripts or superscripts in GMT or PyGMT by using @-text@- or @+text@+, respectively. See also the table in the GMT documentation for text — GMT 6.5.0 documentation (generic-mapping-tools.org)

Please see the two small examples below as orientation:

import pygmt

#------------------------------------------------------------------------------
# subcript            
fig = pygmt.Figure()

fig.basemap(
    region=[6, 12, 42, 47],
    projection="M10c",
    frame="f",
)

fig.colorbar(
    cmap="roma",
    frame="+ltext@-subscript@-",
    position="JMC+h",  # horizontal colorbar
)

fig.show()

#------------------------------------------------------------------------------
# superscript           
fig = pygmt.Figure()

fig.basemap(
    region=[6, 12, 42, 47],
    projection="M10c",
    frame="f",
)

fig.colorbar(
    cmap="roma",
    frame="+ltext@+superscript@+",
    position="JMC+h",  # horizontal colorbar
)

fig.show()

Hello Yvonne,

Thanks a lot for the prompt reply. I just tried it, and it works fine for me!

I think we can close this issue now. Thank you!

Cheers

Hello @Y-Tang99,

pleased I could help out!

Cheers,
Yvonne