python 安装缺乏的包
命令行
pip install -U numpy
pip install -U pands
pip install -U matplotlib
pip install -U sklearn
python 支持中文
1.修改matplotlibrc文件
进入Python安装目录下的Lib\site-packages\matplotlib\mpl-data目录,打开matplotlibrc文件,删除font.family
和font.sans-serif
两行前的#
,并在font.sans-serif
后添加微软雅黑字体(Microsoft YaHei),代码如下:
3 中文字符串的地方前面加u,plt.title(u"这是一个图表")
4.为保险起见,到C:\Windows\Fonts\中找到微软雅黑对应的字体文件msyh.ttf(Window 8系统是msyh.ttc,也可从网上下载msyh.ttf),将其复制到%Python_Home%\Lib\site-packages\matplotlib\mpl-data\fonts\ttf\目录下
方法一:代码中指定中文字体
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import matplotlib
zhfont1 = matplotlib.font_manager.FontProperties(fname='/usr/share/fonts/cjkunifonts-ukai/ukai.ttc')
plt.xlabel(u"横坐标xlabel",fontproperties=zhfont1)