Linux, Matplotlib related issues and workarounds

Source: Internet
Author: User

1. When running the Matplotlib program under Linux, install the matplotlib.

Continue with the installation according to different Linux systems:

Debian/ubuntu:sudo apt-get install python-matplotlib

Fedora/redhat:sudo yum install python-matplotlib

2. Run the Matplotlib program times with the following error:

Solution, add the following code to the file header

import matplotlib

matplotlib.use(‘Agg‘)

3. Generated picture, cannot display Chinese, show square in picture

Workaround:

1. In Ubutu, confirm the existing Chinese font library in the system:
$ fc-list :lang=zh
2. Terminal display:

$ fc-list :lang=zh 

/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf: Droid Sans Fallback:style=Regular

Can see only one font, Droid Sans Fallback

2. 在脚本中添加代码

import matplotlib as mpl

mpl.rcParams[‘font.sans-serif‘] = [‘Droid Sans Fallback‘]

3. Configuration of the Matplotlibrc file

Under Linux, go to the python command prompt:

Import Matplotlib

Matplotlib.matplotlib_fname ()

It will then print out where the Matplotlibrc file is located, and the default location (/etc) is probably the case:

such as: U '/usr/local/lib/python2.7/dist-packages/matplotlib-1.5.1-py2.7-linux-i686.egg/matplotlib/mpl-data/ MATPLOTLIBRC '

Open this file with administrator privileges and find

#font. Serif:
#font. Family:

The two lines, uncomment it, save.

Section Reference Links: http://blog.csdn.net/xexiyong/article/details/51970060

Linux, Matplotlib related issues and workarounds

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.