-
Notifications
You must be signed in to change notification settings - Fork 748
Is it possible to add support for CJK fonts #16
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
Comments
I don't have any experience with CJK fonts, but I think that it's probably something to do with the Latex font rendering. Does it work properly if you disable Latex? plt.style.use(['science', 'no-latex']) |
Unlucky, it seems to be useless. When using LaTeX, I notice it's using pdfTeX, which poorly supports CJK rendering and hard to tweak. However, using no-latex still can not fix the issue directly, but having some tweaks in .mlpstyle could be helpful. I will try fixing it & make a PR later. Hopefully, I will also try fixing LaTeX rendering issue. :D |
Hi @Alraemon Did you have any luck getting this to work? |
Hi @garrettj403 There is no font fallback implementation in There would be two possible ways to use CJK fonts for plotting:
To use mixed CJK characters and Latins characters with There is an example in the Colab jupyter notebook matplotlib.use('pgf') # stwich backend to pgf
matplotlib.rcParams.update({
"pgf.texsystem": "xelatex",
"text.usetex": True, # use default xelatex
"pgf.rcfonts": False, # turn off default matplotlib fonts properties
"pgf.preamble": [
r'\usepackage{fontspec, xeCJK}',
r'\setmainfont{Latin Modern Roman}',# EN fonts Romans
r'\setCJKmainfont{SimHei}',# set CJK fonts as SimSun
r'\setCJKsansfont{SimHei}',
r'\newCJKfontfamily{\Song}{SimSun}',
]
}) The script above would export the |
Update@Hsins made a pull request to add support for CJK fonts (see #29). The new Example 14 provides an example of this style: The style works well with SC/TC/JP characters, but there are some errors with Korean characters (see discussion in #29). I reopened this issue in case anyone requires Korean characters. |
Hi @garrettj403 I have tried again to deal with the Korean characters, it seems that errors occur when the character By the way, I must point out that the given list of fonts below is nonsense in most cases (and sorry for that I push it in previous commits) because of the lack of font fallback mechanism in
The Moreover, there are some differences in those Noto Fonts even though each font supports the charsets in other CJK languages: Ref: https://ibe.tw/noto-font/ According to the two reasons, users who use Traditional Chinese can just use the font list below (and as same as to the users who use other CJK languages).
Would you mind to separate the |
Okay, I split Note: When I run example 14, I get the following error message:
This means that th 8000 e PDF files end up being ~20 MB. Do you have the same issue? |
I have that same issue too but the problem can't be solved ourselves. The But it failed to subsetted the CJK fonts we used. The result would be embedded those fonts into the output file and what the sad news is all the CJK fonts are HUGE. This may as same as the result when we need to use FontType 42 and it make the size of PDF file large. For someone who wants to reduce the size of PDF file, just follow the solutions here to convert the PDF file to Ghostscript file then convert it back. $ pdf2ps file.pdf file.ps
$ ps2pdf -dPDFSETTINGS=/prepress file.ps file-optimized.pdf The option -dPDFSETTINGS defines the quality of the produced PDF. Possible options and explanations are listed below:
|
I created a new release (v1.0.7) which includes limited support for CJK characters. There is still the issue that CJK pdf figures are very large but you can follow the instructions above (from @Hsins) to reduce the size of those figures. I don't think there is anything we can do to fix this. Note:
I'll close this issue for now, but feel free to reopen if there are any more problems or ways to improve CJK support. |
Currently, the legends & labels written in CJK characters can not be properly displayed, can this issue be fixed, or any way to override something to get it displayed ?
The text was updated successfully, but these errors were encountered: