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