Solve the problem of matplotlib Chinese display block in Mac system

Source: Internet
Author: User

First, the Mac needs to download the Simhei.ttf font and install it, then follow the steps below to copy the Simhei.ttf to the ~python installation path/site-packages/matplotlib/mpl-data/fonts/ttf directory;

Link: Https://pan.baidu.com/s/1hsGhxmG Password: rste

Two. Then modify the ~python installation path/SITE-PACKAGES/MATPLOTLIB/MPL-DATA/MATPLOTLIBRC file. According to the actual situation changes, find the following two items, remove the previous #, and after the Font.sans-serif Colon plus simhei, save exit.

Font.family:sans-serif

Font.sans-serif:simhei, Bitstream Vera sans, lucida Grande,verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, SA Ns-serif

At the same time will find Axes.unicode_minus, will be true to false, the role is to solve the negative sign '-' Display as a block problem

Three. Add the following two paragraphs to the code

#matplotlib不会每次启动时都重新扫描所有的字体文件并创建字体索引列表,
# So after copying the font file, you need to run the following statement to recreate the font index list
From Matplotlib.font_manager import _rebuild
_rebuild ()
#防止中文乱码问题
mpl.rcparams[' Font.sans-serif ']=[u ' Simhei ']
mpl.rcparams[' Axes.unicode_minus ']=false

Solve the problem of matplotlib Chinese display block in Mac system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.