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

[intro_demand_supply] Bug in matplotlib #30

Closed
mmcky opened this issue Sep 18, 2024 · 8 comments
Closed

[intro_demand_supply] Bug in matplotlib #30

mmcky opened this issue Sep 18, 2024 · 8 comments

Comments

@mmcky
Copy link
Contributor

mmcky commented Sep 18, 2024

Currently the matplotlib figures are not displaying Chinese characters correctly

Screenshot 2024-09-18 at 10 54 28 am

@longye-tian can you apply @HumphreyYang fix to the top code block to see if it fixes this issue #5

@longye-tian
Copy link
Contributor

longye-tian commented Sep 19, 2024

Hi Matt @mmcky ,

Thanks for point this out. I'll try to fix this.

After using @HumphreyYang's method, the issue persist.

In my local jupyter notebook, it looks okay. But when I view the deployment online it still doesn't work.

Best,
Longye

@HumphreyYang
Copy link
Contributor

HumphreyYang commented Sep 22, 2024

In addition to adding the code in the code cells, on the Linux machine/server, we need to add the Chinese font by adding the font SimHei.ttf to the mpl directory
(i.e.,

/home/humphrey/anaconda3/envs/quantecon/lib/python3.1/site-packages/matplotlib/mpl-data/fonts/ttf

)

I managed to make it work on my Linux server : )

(see more at https://stackoverflow.com/questions/40290004/how-can-i-configure-matplotlib-to-be-able-to-read-fonts-from-a-local-path)

@mmcky
Copy link
Contributor Author

mmcky commented Sep 23, 2024

thanks @HumphreyYang I have seen this also -- perhaps we can use system wide fonts and passing a fonts property to the legend?

https://stackoverflow.com/questions/39630928/how-to-plot-a-figure-with-chinese-characters-in-label

@HumphreyYang
Copy link
Contributor

thanks @HumphreyYang I have seen this also -- perhaps we can use system wide fonts and passing a fonts property to the legend?

https://stackoverflow.com/questions/39630928/how-to-plot-a-figure-with-chinese-characters-in-label

Hi @mmcky,

I tried this too, but I still need to add the ttf file into the mpl folder to make it work : (

@HumphreyYang
Copy link
Contributor

HumphreyYang commented Sep 23, 2024

This issue is solved by adding

import matplotlib as mpl
FONTPATH = "fonts/SourceHanSerifSC-SemiBold.otf"
mpl.font_manager.fontManager.addfont(FONTPATH)
plt.rcParams['font.family'] = ['Source Han Serif SC']

to imports at the beginning of the lecture.

See #35.

@mmcky
Copy link
Contributor Author

mmcky commented Sep 27, 2024

Great -- that's what I thought. Cheers.

@HumphreyYang
Copy link
Contributor

Hi @mmcky,

I found some PRs have not yet been updated to this solution. Maybe we should keep an eye on this?

@mmcky
Copy link
Contributor Author

mmcky commented Sep 27, 2024

#61

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

No branches or pull requests

3 participants