Chinese display of matplotlib in Ubuntu

Source: Internet
Author: User

It's really hard to be tortured by the Chinese display of matplotlib. Briefly write down the solution to prevent future configuration from being too tight.

My environment: The system is Ubuntu 13.04, Python is built-in, and matplotlib is installed by apt. Chinese fonts have been installed before.

First, Encoding Problems

Add the encoding declaration to the second line of Python code (the encoding declaration can be placed in the first or second line, but the first line is placed in shebang ):

 

By the way, let's take a look at how to view the current encoding in Emacs:

M-x describe-coding-system
Then there is a font problem.

Copy/etc/matplotlibrc ~ /. Matplotlibrc /. If the configuration item is invalid, delete it ~ /. Matplotlibrc/matplotlibrc.

Configure the font in matplotlibrc:

font.family: sans--serif: WenQuanYi Micro Hei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

Added the Chinese font of wenquanyi micron black. The running program is still square --

Check whether the system has the following Font:

fc-list |  WenQuanYi

Have this font:/usr/share/fonts/truetype/wqy/wqy-microhei.ttc: WenQuanYi Micro Hei, WenQuanYi micron black, WenQuanYi micron Black: style = Regular

Check whether matplotlib finds the font:

 ~/.matplotlib/fontList.cache |  WenQuanYi

No ......

--------------------------------

Cause of speculation: When matplotlib finds the system font, it does not match the ttc font file.

 ~/.matplotlib/fontList.cache |  

No output.

Solution 1

The violent method is to directly change the ttc font to the ttf font:

  wqymicrohei.ttc wqymicrohei.ttf

Delete fontList. cache and run it again to display Chinese characters. However, an error occurred while saving the image as an eps: TrueType font is missing table. Because that ttf is not a ttf file ......

Solution 2

Find an online conversion website and convert the ttc font file to the ttf file. This is my website: http://www.files-conversion.com/font-converter.php

Copy the converted ttf file to/usr/share/fonts. Delete fontList. cache and run it again to display Chinese characters and save the eps images.

 

The ultimate solution should be to enable matplotlib to automatically load the ttc font file, but no configuration is found. Does anyone know how to share it?

Chinese support for software in Linux is still a problem.

Related Article

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.