How to display Russian text on plots with PyGMT

Hello!
I’m trying plot with labels in Russian language but I get squiggles.
Used software: OS Windows 10 / PyGMT v0.7.0 / Python 3.9.13 (Jupyter Notebook).

I try use this code for config:

pygmt.config(
    GMT_LANGUAGE="RU",
    PS_CHAR_ENCODING="ISO-8859-5",
    MAP_GRID_CROSS_SIZE_PRIMARY=0.5
)

but it didn’t work.

However, text elements from txt file work nice.
fig.text(textfiles="seas_ru.txt", angle=True, font=True, justify=True), txt file has ISO-8859-5 encoding.

Please help.

Hi @Alex, thanks for trying PyGMT! Could you copy a few lines from seas_ru.txt and paste it here? That will make it easier for us to help test things.

These related posts might help:

cc @CraneBoba and @uleysky who might be able to help.

I tried a quick script like below, but it doesn’t seem to be printing the Russian characters correctly:

import pygmt
# %%
fig = pygmt.Figure()
with pygmt.config(
    GMT_LANGUAGE="RU", PS_CHAR_ENCODING="ISO-8859-5", MAP_GRID_CROSS_SIZE_PRIMARY=0.5
):
    fig.text(x=147, y=55, text="Россия", region=[145, 150, 54, 56], frame=True)
fig.savefig("russian_text.png")
fig.show()

gives

In your example, the variable PS_CHAR_ENCODING is ignored and UTF-8 encoded text is written to the eps file. I don’t use pygmt and don’t know how to fix this. I would suggest using gmt on the command line, it’s easier to control what’s going on and fix it if necessary.

Hello, here text file - seas_ru.txt (97 Bytes),

151 40 33 18p,Helvetica,black CM Тихий океан\n\n
151 52 0 12p,Helvetica,black CM Охотское море\n