-
Notifications
You must be signed in to change notification settings - Fork 718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CJK Noto Fonts - Chinese and Korean don't work - Font 'default' does not have a glyph #84
Comments
I have same problem in using simplified chinese。
|
Hi @machel7 and @downeykking , I won't be able to troubleshoot it for some weeks due to personal constraints. Till I return, you can have a look at this wiki entry, it may hint you in solving this issue. Have a look at the issue mentioned in the wiki, in some examples, it uses a "pgf" backend, that might solve it. Whatever you find useful, please let us know. |
Well, I had a little time to look into it, enough I believe. Issue confirmed, SciencePlots docs are outdatedI've been doing the wiki step by step (on Ubuntu 22.04, python 3.9), and found I can't run this snippet: >>> import matplotlib.font_manager as fm
>>> fm._rebuild()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'matplotlib.font_manager' has no attribute '_rebuild' Went to matplotlib's repo and found this issue, which is addressed in this PR, still draft, has been some time since last update. They've got some problems with the font_manager module, can't really tell what happened to Some troubleshootingI've been trying matplotlib versions prior to the
TLDRThe problem is that matplotlib is not reloading the fonts and it can't find the noto CJK (well, only the Japanese in v3.6.3). Whatever solution you find, please, let us know so the next person to have that problem has the reference. |
I encountered the same problem when using Simplified Chinese. Finally, I used
Hope it helps! |
Hi @FunClip! Thank you very much for letting us know! I think I will deprecate our CJK styles, as I don't have both time & motivation to try to fix that. I will update the wiki in shortly. Again, thank you. |
Finally it worked with CJK font! Be careful to set import matplotlib as mpl
import matplotlib.pyplot as plt
import scienceplots
plt.style.use(["science"])
mpl.use("pgf")
params = {
"font.family": "serif",
"text.usetex": True,
"pgf.rcfonts": False,
"pgf.texsystem": "xelatex",
"pgf.preamble": "\n".join(
[
r"\usepackage{fontspec, xeCJK}",
# r"\setmainfont{Times New Roman}",
r"\setCJKmainfont{SimSong}",
r"\setCJKsansfont{Hei}",
]
),
}
mpl.rcParams.update(params)
x = [1, 2, 3, 4, 5, 6]
y = [1, 4, 9, 16, 25, 36]
plt.figure()
plt.plot(x, y)
plt.title("中文标题 xyz 123")
plt.savefig("test.pdf") ![]() It seems that the |
Thank you very much, I have used mplfonts to solve the problem. Very appreciate your favor.
从 Windows 版邮件<https://go.microsoft.com/fwlink/?LinkId=550986>发送
…________________________________
发件人: Jeremy Feng ***@***.***>
发送时间: Sunday, November 26, 2023 8:16:11 PM
收件人: garrettj403/SciencePlots ***@***.***>
抄送: Seven ***@***.***>; Mention ***@***.***>
主题: Re: [garrettj403/SciencePlots] CJK Noto Fonts - Chinese and Korean don't work - Font 'default' does not have a glyph (Issue #84)
Finally it worked with CJK font! Be careful to set "pgf.preamble". I use the code from matplotlib documentation<https://matplotlib.org/stable/gallery/userdemo/pgf_preamble_sgskip.html>.
import matplotlib as mpl
import matplotlib.pyplot as plt
import scienceplots # noqa: F401
plt.style.use(["science"])
mpl.use("pgf")
preamble = [
r"\usepackage{fontspec}",
r"\setmainfont{Hei}",
]
params = {
"font.family": "serif",
"text.usetex": True,
"pgf.rcfonts": False,
"pgf.texsystem": "xelatex",
"pgf.preamble": "\n".join(
[
r"\usepackage{fontspec, xeCJK}",
# r"\setmainfont{Times New Roman}",
r"\setCJKmainfont{SimSong}",
r"\setCJKsansfont{Hei}",
]
),
}
mpl.rcParams.update(params)
x = [1, 2, 3, 4, 5, 6]
y = [1, 4, 9, 16, 25, 36]
plt.figure()
plt.plot(x, y)
plt.title("中文标题 xyz 123")
plt.savefig("test.pdf")
image.png (view on web)<https://github.com/garrettj403/SciencePlots/assets/44312563/99956ccc-9f86-4e6d-8656-310b26b9cd64>
It seems that the pgf backend can only save the figure to pdf format. I'm wondering how to save the figure as png, svg, or other formats.
―
Reply to this email directly, view it on GitHub<#84 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFQGAGCSAHF6264J7EP2EGLYGMXIXAVCNFSM6AAAAAATRWRKOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRWG43DQMBSGE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I've practically exhausted all methods, and only this approach has proven successful for me. (WSL2, ubuntu2004) |
I tried this, but unfortunately it didn't work for me. I'm on Windows 11, and I use the following code to solve the problem temporarily: plt.style.use(['science', 'grid', 'cjk-sc-font', 'no-latex'])
plt.rcParams.update({
'font.family': 'Noto Serif CJK SC',
'axes.unicode_minus': False,
}) |
After following the FAQ Installing CJK fonts, I have already installed
fonts-noto-cjk
.But when i tried the examples like:
Only
cjk-jp-font
made sense.Noto Serif CJK SC
andNoto Serif CJK TC
both failed.How can I solve this problem? Thanks in advance.
The text was updated successfully, but these errors were encountered: