Skip to content
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

How to display Chinese title? #399

Closed
run27017 opened this issue May 31, 2021 · 4 comments
Closed

How to display Chinese title? #399

run27017 opened this issue May 31, 2021 · 4 comments
Labels
question Further information is requested

Comments

@run27017
Copy link

run27017 commented May 31, 2021

It seems cannot display Chinese well, following is the test code:

import mplfinance as mpf

mpf.plot(df, title="如何显示中文")

df is the stock trading code looks like:

                     open   high    low     close  pre_close  change  pct_chg        vol        amount
date
2021-05-24  23.48  23.60  23.19  23.48      23.49   -0.01  -0.0426  343935.63  8.060922e+05
2021-05-25  23.54  24.73  23.45  24.60      23.48    1.12   4.7700  972374.62  2.363146e+06
2021-05-26  24.64  25.12  24.50  25.01      24.60    0.41   1.6667  919263.78  2.286540e+06
2021-05-27  24.91  25.16  24.52  24.79      25.01   -0.22  -0.8796  504091.36  1.246712e+06
2021-05-28  24.68  24.71  24.16  24.50      24.79   -0.29  -1.1698  492400.73  1.200523e+06

My machine is openSUSE Tumbleeweed, and the python version is 3.8.10. The version of mpf lib is 0.12.7a17.

@run27017 run27017 added the question Further information is requested label May 31, 2021
@DanielGoldfarb
Copy link
Collaborator

Ehen mplfinance applies its styles, it first appies a matplotlib style and these matplotlib styles modify rcParams.

The way to make this work would be to include the desired font.family in the style. For example, suppose you wanted to use style 'yahoo' , but with Chinese characters. You should be able to do so like this:

rcpdict = { 'font.family' : 'Noto Sans CJK SC' }
s = mpf.make_mpf_style(base_mpf_style='yahoo',rc=rcpdict)
mpf.plot(data,...,style=s)

Please let me know if that works for you.
Thank you. All the best. --Daniel

@run27017
Copy link
Author

run27017 commented May 31, 2021

But it doesn't work:

rcpdict = { 'font.family' : 'Noto Sans CJK SC' }
s = mpf.make_mpf_style(base_mpf_style='yahoo',rc=rcpdict)
mpf.plot(df, title="如何显示中文", style=s)

About the figure:

Figure_1

What does 'Noto Sans CJK SC' mean? Is it related to specific machine or operating system?

@run27017
Copy link
Author

run27017 commented May 31, 2021

I have solved the issue through adjusting the font.family:

rcpdict = { 'font.family' : ['AR PL UKai CN', 'sans-serif']}

The string 'Noto Sans CJK SC' should be a font name but my system doesn't have. So, thank you for your prompt, Daniel. You're very nice.

At last, for any other who is bored by this issue, you should apply the style like Daniel does. And the font.family should be changed to machine related one. You are able to list the Chinese font families using:

$ fc-list :lang=zh family

@DanielGoldfarb
Copy link
Collaborator

@run27017
Thank you very much for adding the details about the solution. Have a great day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants