hupili / python-for-data-and-media-communication-gitbook

An open source book on Python tailed for communication students with zero background
115 stars 62 forks source link

About displaying Chinese fonts in graphs #89

Closed im-mengyuli closed 5 years ago

im-mengyuli commented 5 years ago

Troubleshooting

Describe your environment

Describe your question

I want to make a wordcloud picture of Chinese words using matplotlib. But the output picture is garbled and Chinese words cannot display. Even I have tried the two potential solutions (### https://github.com/hupili/python-for-data-and-media-communication-gitbook/blob/7fad4125cbde74714dbe0da1f71649680d24d7ee/module-matplotlib.md and https://github.com/hupili/python-for-data-and-media-communication/blob/93ff76364e0374aaacf75f766efb4736d7a357b7/matplotlib-examples/Chinese%20Font.ipynb) in Github, they do not work.

The minimum code (snippet) to reproduce the issue

Please refer to the following link https://github.com/ClioLI/Thorny-issues-of-Python

hupili commented 5 years ago

You need to load the font in the wordcloud function. It does not go through the matplotlib. That is why even if you can plot Chinese on matplotlib, the wordcloud is still problematic.

    wc = wordcloud.WordCloud(background_color="white",max_words=3000,max_font_size=60, random_state=40)

Please refer to In [538] of this notebok

im-mengyuli commented 5 years ago

Thanks a lot!

hupili commented 5 years ago

@ClioLI does this solve your issue? If so @ChicoXYC please merge to FAQ and leave pointers here.

im-mengyuli commented 5 years ago

Yes, the problem has been solved and Yucan said he will merge this to FAQ.

ChicoXYC commented 5 years ago

merged into FAQs: https://github.com/hupili/python-for-data-and-media-communication-gitbook/blob/master/module-matplotlib.md#display-chinese-characters-when-plotting-tag-cloud

hupili commented 5 years ago

It is better to put into module-wordcloud. In essence, it is the wordcloud issue, not matplotlib issue.

After the new FAQ page is created, you can link from module-matplotlib to module-wordcloud, leaving a message:

There is a similar issue about Chinese characters (CJK characters) when you use wordcloud. Please refer to this section for the solution.

We keep on improving categorisation and inter-linking between those topics.

ChicoXYC commented 5 years ago

@hupili merged into FAQs https://github.com/hupili/python-for-data-and-media-communication-gitbook/blob/master/module-wordcloud.md#display-chinese-characters-when-plotting-tag-cloud