Dear all,
Due to the major slowdown of PyGMT in WSL1(this question), I decided to move to PyGMT on Windows, however, the running speeds of PyGMT programs increased significantly, I meet a new problem now. I want to display Chinese characters on my plot, and I have successfully configured the Chinese fonts for Ghostscprit by referring to this link. I can now add Chinese fonts to my plot via a pre-written text file (ANSI coding) including Chinese characters (black characters on the plot), but I can’t add Chinese directly to the plot through Python scripts (red garbled characters).
Here is the text file.
# text.txt
# x y text
1 1 中文测试
Here is my python script.
import numpy as np
import pygmt
fig = pygmt.Figure()
pygmt.config(PS_CHAR_ENCODING="Standard+")
fig.basemap(region = [0,2,0,4], projection="X4c/6c" ,frame=['xaf','yaf'])
fig.text(textfiles="text.txt",font="13p,40,black")
fig.text(text="中文测试", x=1,y=2,font="13p,40,red")
fig.text(text="English Test", x=1, y=3, font="13p,40,green")
fig.savefig("cn-test.png",dpi=400)
I also tried to save the python script as ANSI coding, but I get the following error when I run the code.
SyntaxError: Non-UTF-8 code starting with '\xd6' in file E:\python\pygmt\cn\cn-test.py on line 9, but no encoding declared; see https://python.org
/dev/peps/pep-0263/ for details
I can add Chinese directly to my plot when I run python on the Linux platform and no need to set a text file or a python script to ANSI coding. Can anyone give me some advice on how to add Chinese to the plot directly from a Python script on Windows?
Thanks in advance.