10 months ago

When I was trying to use Chinese characters for a chart's title, matplotlib displayed a bunch of squares. Here are the steps to solve it.

Step 1: Find matplotlibrc

I am using virtualenv, so for me the path is:


The key part is /lib/python3.5/site-packages/matplotlib/mpl-data

Step 2: Modify matplotlibrc

Uncomment font.family and font.sans-serif, then add the following fonts before Bitstream Vera Sans:

PingFang SC, Hiragino Sans GB, Microsoft YaHei,

It should look like this:

font.sans-serif     : PingFang SC, Hiragino Sans GB, Microsoft YaHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

If you have a ipyton notebook open, you have to close and reopen it to make this change effective. Otherwise this is it :D

← Install Python3 and virtualenv on Mac Python3's pass more than one parameter to lambda function →
comments powered by Disqus