Closed Hsins closed 4 years ago
Hi @Hsins
Thank you very much for your contribution. Following your instructions in README
, I was able to install the CJK fonts and run example 14. (I haven't tried example 15 yet.)
I'll create a new release of SciencePlots soon to add your changes to the PyPI version.
Hi @garrettj403
It's really glad to hear that you successfully run example 14 with that instructions. :)
By the way, the little trouble I mentioned is about the difference between example 14 and example 15.
電壓
and 電流
) and it renders with original matplotlib
instead of XeLaTeX Engine.电压
and 电流
), Traditional Chinese (電壓
and 電流
), Japanese (電圧
and 電気
) and Korean (전압
and 전류
). And it renders with the XeLaTeX Engine so that should use the option backend='pgf'
. Although the Example 15 works fine in my machine (as you see the result I uploaded that fig15.pdf before). It always gives the error with the message UnicodeEncodeError: 'utf-16-be' codec can't encode character '\ud98a' in position 51204: surrogates not allowed
when I try to use the same texts with 电压電壓電圧전압
and 电流電流電気전류
in Example 14.
It seems that there was not a missing glyphs problem because Example 15 works fine and the Guidelines for Using Noto page said each font supports all four languages:
It is recommended to use "Noto Sans CJK {JP, KR, SC, TC}" rather than "Noto Sans {JP, KR, SC, TC}", unless space/latency is very restricted. Each of the font families "Noto Sans CJK {JP, KR, SC, TC}" supports all four languages, but has a different default language. Learn more about Noto CJK
So I'm sorry to say that I can't guarantee the cjk-fonts
style would work fine in Japanese, Korean, or even Simplified Chinese...
Although the Example 15 works fine in my machine (as you see the result I uploaded that fig15.pdf before). It always gives the error with the message UnicodeEncodeError: 'utf-16-be' codec can't encode character '\ud98a' in position 51204: surrogates not allowed when I try to use the same texts with 电压電壓電圧전압 and 电流電流電気전류 in Example 14.
I get this error as well when I include the Korean characters. Example 14 works for me with the TC/SC/JP characters.
I can run example 15, but the Korean characters don't render (they just appear as boxes) and I have to use your PGF preamble:
import matplotlib
matplotlib.use('pgf') # switch backend to pgf
matplotlib.rcParams.update({
"pgf.preamble": [
"\\usepackage{fontspec}",
'\\usepackage{xeCJK}',
r'\setmainfont{Times New Roman}', # EN fonts Romans
r'\setCJKmainfont{SimHei}', # set CJK fonts as SimSun
r'\setCJKsansfont{SimHei}',
r'\newCJKfontfamily{\Song}{SimSun}',
]
})
I get this error as well when I include the Korean characters. Example 14 works for me with the TC/SC/JP characters.
I can run example 15, but the Korean characters don't render (they just appear as boxes) and I have to use your PGF preamble:
import matplotlib matplotlib.use('pgf') # switch backend to pgf matplotlib.rcParams.update({ "pgf.preamble": [ "\\usepackage{fontspec}", '\\usepackage{xeCJK}', r'\setmainfont{Times New Roman}', # EN fonts Romans r'\setCJKmainfont{SimHei}', # set CJK fonts as SimSun r'\setCJKsansfont{SimHei}', r'\newCJKfontfamily{\Song}{SimSun}', ] })
I don't think it's a problem with the setting of style params but the problem with the font file or even the LaTeX Engine. So just leave the issue for anyone who needs to use Korean in their plots. 😂😂😂😂😂
I can run example 15, but the Korean characters don't render (they just appear as boxes) and I have to use your PGF preamble:
import matplotlib matplotlib.use('pgf') # switch backend to pgf matplotlib.rcParams.update({ "pgf.preamble": [ "\\usepackage{fontspec}", '\\usepackage{xeCJK}', r'\setmainfont{Times New Roman}', # EN fonts Romans r'\setCJKmainfont{SimHei}', # set CJK fonts as SimSun r'\setCJKsansfont{SimHei}', r'\newCJKfontfamily{\Song}{SimSun}', ] })
I forgot to explain what the PGF preamble does.
fontspec
for XeLaTeX
engine provides users to use certain fonts for rendering texts.xeCJK
for XeLaTeX
engine provides users to set up different font in CJK characters and Latin characters.
setmainfont
for Latin characterssetCJKmainfont
for CJK characters.The fonts are given to setmainfont
and setCJKmainfont
can be a font-family name of the system fonts or a path of certain *.ttf/*.otf
font file. If you follow the instructions I wrote in the FAQ section (the Noto {Sans/Serif} CJK {TC/SC/JP/KR}
fonts would be installed to your machine), you should use the PGF preamble below:
matplotlib.rcParams.update({
"pgf.preamble": [
"\\usepackage{fontspec}",
'\\usepackage{xeCJK}',
r'\setmainfont{Times New Roman}', # EN fonts Romans
r'\setCJKmainfont{Noto Serif CJK TC}', # set CJK fonts as Noto Serif CJK TC
]
})
This pull request is about the issue https://github.com/garrettj403/SciencePlots/issues/16.
"Noto Serif CJK {TC, SC, JP, KR}"
is not pre-installed in any operating systems. Users need to install those fonts before using thecjk-fonts
style.backend='pgf'
instead ofno-latex
. I got into some trouble with theno-latex
option although there are no missing glyphs in the font.Finally, the result:
jpg
format)