question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The solution of display chinese in seaborn plot

See original GitHub issue

As #829 and #592 said, the reason is “seaborn override default fonts specified in matplotlibrc configs”. Thus, you can set the default seaborn font style after import the seaborn as follows:

import seaborn as sns sns.set_style("darkgrid",{"font.sans-serif":['simhei', 'Arial']})

The simhei is the chinese font, and make sure the simhei.ttf already in your “Lib\site-packages\matplotlib\mpl-data\fonts\ttf” folder.

This method just change the seaborn font setting temporarily, however I do not know how to do that permanently.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:14
  • Comments:11

github_iconTop GitHub Comments

17reactions
cqcn1991commented, Dec 7, 2016

Thanks @githubzhanglei , it works fine under python 3, here is my result. Just to be sure to set mpl first and then set seaborn.

import matplotlib as mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
mpl.rcParams['font.serif'] = ['SimHei']
import seaborn as sns
sns.set_style("darkgrid",{"font.sans-serif":['simhei', 'Arial']})

qq

2reactions
Qiuzhuangcommented, May 13, 2019

If still seeing error after putting SimHei.ttf into site-packages/matplotlib/mpl-data/fonts/ttf, you might try to clear font cache. For centos, just go to ~/.cache/matplotlib and remove cached font list file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Seaborn, Matplotlib, plot Chinese error - python - Stack Overflow
Try to set matplotlib font and then set seaborn.And make sure that font is available in your system.
Read more >
How to plot a figure with Chinese Characters in label - Kaggle
When I draw a figure with Chinese Character (Japanese Kanji) and it doesn't work! ... Anyone know how to display the Kanji in...
Read more >
How to Display Chinese Character in matplotlib - Beverly Wang
Method 2: There is another way to work around, too. Manually specify the font file location and set font properties and then specify...
Read more >
Data Visualisation with Python: Seaborn and Scatter Plots
This course will teach you how to bring big data sets to life through data visualisation using the powerful Python programming language.
Read more >
Chapter 37 Interview questions for data visualization
Seaborn helps data scientists create statistically and aesthetically appealing meaningful plots. The answer to this question varies based on the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found