當前位置:編程學習大全網 - 源碼下載 - python matplotlib怎麽用

python matplotlib怎麽用

使用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()

如果

  • 上一篇:贊呢?有用嗎?
  • 下一篇:簡單的編程小遊戲教程
  • copyright 2024編程學習大全網