python matplotlib怎么用

如题所述

第1个回答  2016-04-06
使用python的包matplotlib来画图
浏览:255
|
更新:
2015-10-24 22:10
1
2
3
4
5
6
7
分步阅读
python中的matplotlib可以很快的帮助我们作出图,
为此我们给出matplotlib的安装步骤和一个小例子来展示其功能
工具/原料
python3.4
numpy包
matplotlib包
依赖包:pyparsing、dateutil、scipy
方法/步骤
python安装(之前写过一篇关于python的安装,这里不重复介绍)
(1) 如何下载?百度---> Python官网
(2) 版本:python-3.4.3.amd64 exe文件直接点哦
(3) 目录:D:\Python34
为python配置了环境变量:D:\Python34\Scripts;D:\Python34
(4) 命令行输入:python 有反应表示成功
说明:matplotlib还没有匹配python3.5的版本,我的电脑为64位
0Python安装学习指南
软件包下载:
因为涉及到众多包的下载,以及其中的版本和电脑位数问题特介绍如下( 注意加粗的字体):
(1) numpy numpy-1.10.1+mkl-cp34-none-win_amd64.whl
(2) matplotlib matplotlib-1.4.3.win-amd64-py3.4b/matplotlib-1.4.3/windows/
(3) 依赖包:pyparsing、dateutil、scipy

声明:以上软件地址可自行百度搜索
附注:图一为matplotlib 、图二为numpy 下载界面的选择

软件包numpy的安装:
1 命令行输入【完整的路径=numpy 在你电脑的绝对路径】
pip install 完整的路径\numpy -1.10.1+mkl-cp34-none-win_amd64.
2 验证:python编辑下 python>>
from numpy import *

安装matplotlib:
matplotlib-1.4.3.win-amd64-py3.4
因为下载的是exe文件,点击一路执行即可

依赖包的安装:
在命令行里逐行输入如下命令:软件包的绝对路径
1 pip install 绝对路径\pyparsing-2.0.3-py3-none-any.whl
2 pip install 绝对路径\python_dateutil-2.4.2-py2.py3-none-any.whl
3 pip install 绝对路径\matplotlib依赖\scipy-0.16.0-cp34-none-win_amd64.whl

验证是否安装成功:
1 在python编辑状态下导入安装的包:
import matplotlib
import numpy
import scipy
import pyparsing
import matplotlib.pyplot as plt
2 如果缺少six
在安装完毕scipy之后把../Python34/Lib/site-packages/scipy/lib中的six.py six.pyc six.pyo三个文件拷贝到.../Python34/Lib/site-packages
案例1:
import matplotlib.pyplot as plt
x = [0, 1, 2, 3, 4, 5]
y = [0.1, 0.2, 0.2, 0.3, 0.2, 0.1]
y2 = [0.2, 0.2, 0.3, 0.2, 0.3, 0]
plt.plot(x, y, 'b', x, y2, 'g')
plt.show()

案例2:
import matplotlib.pyplot as plt
import math
x=[]
y=[]
num=0.0
while num < math.pi * 4:
y.append(math.sin(num))
x.append(num)
num += 0.1
plt.plot(x, y, 'b')
plt.show()

如果
相似回答