最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python繪制二維曲線的日常應(yīng)用詳解

 更新時(shí)間:2019年12月04日 10:34:36   作者:grey_csdn  
今天小編就為大家分享一篇Python繪制二維曲線的日常應(yīng)用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

使用Python繪制出類似Excel或者M(jìn)ATLAB的曲線還是比較容易就能夠?qū)崿F(xiàn)的,需要用到的額外庫有兩個(gè),numpy和matplotlib。使用這兩個(gè)模塊實(shí)現(xiàn)的曲線繪制其實(shí)在一定程度上更像是MATLAB的plot功能,不過今天看了一下matplotlib網(wǎng)站上的信息,現(xiàn)在的功能更為強(qiáng)勁了,而且已經(jīng)支持三維圖像的繪制。

模塊庫的安裝非常簡單,我使用的Mac,在Mac上用pip進(jìn)行了兩個(gè)模塊庫的安裝都十分順暢。相信其他平臺(tái)基本上也都這樣,如果能夠聯(lián)網(wǎng),這種安裝方式是十分推薦的,確實(shí)是簡單。

我用Python讀取我自己日常運(yùn)動(dòng)的數(shù)據(jù),數(shù)據(jù)以Numbers的方式進(jìn)行統(tǒng)計(jì),導(dǎo)出成Excel文件。為了能夠讀取Excel文件,我又安裝了xlrd模塊庫。

從matplotlib的網(wǎng)站上抄了一小段代碼簡單做了一下修改,加入了數(shù)據(jù)讀取以及簡單的計(jì)算,代碼如下:

#!/usr/bin/python



 import numpy as np

 import matplotlib.pyplot as plt

 from xlrd import open_workbook



 def SportLine(excel_file):

     days_year  = []

     target_km  = []

     records   = []

     sum_records = []

     pct_records = []

     target_pct  = []



     fig,axs = plt.subplots(3)



     for i in range(365):

         days_year.append(i)



     for day in days_year:

         target_km.append(float(day)/365.0 * 1000.0)



     # read record data

     book = open_workbook(excel_file)

     sheet = book.sheet_by_name('record')

     rows_num = sheet.nrows

     cols_num = sheet.ncols

     for row_num in range(3,368):

         try:

             records.append(float(sheet.cell(row_num,1).value))

         except:

             records.append(0.0)



     # calculate sum of records

     sum_record = 0.0

     for each_record in records:

         sum_record += each_record

         sum_records.append(sum_record)



     # calculate pct of all

     for each_sum in sum_records:

         pct_records.append(each_sum / 1000.0)



     # calculate target pct

     for day in range(1,366):

         target_pct.append(float(day)/365.0)



     # plot target and sum trend

     ax = axs[0]

     ax.plot(days_year,sum_records)

     ax.plot(days_year,target_km)

     ax.set_title('distance-year-km')

     ax.grid(True)



     # plot record

     ax = axs[1]

     ax.plot(days_year,records)

     ax.set_title('distance-day-km')

     ax.grid(True)



     # plot percentage

     ax = axs[2]

     ax.plot(days_year,pct_records)

     ax.plot(days_year,target_pct)

     ax.set_title('pct-100%')

     ax.grid(True)

     plt.show()



 SportLine('records.xlsx')

我的運(yùn)動(dòng)數(shù)據(jù)記錄電子表格格式如下:

程序運(yùn)行,畫出的曲線如下:

基本差不多了,后面需要做的只有細(xì)節(jié)上的修正了。

以上這篇Python繪制二維曲線的日常應(yīng)用詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python Handler處理器和自定義Opener原理詳解

    Python Handler處理器和自定義Opener原理詳解

    這篇文章主要介紹了Python Handler處理器和自定義Opener原理詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03
  • python 如何停止一個(gè)死循環(huán)的線程

    python 如何停止一個(gè)死循環(huán)的線程

    這篇文章主要介紹了python 如何停止一個(gè)死循環(huán)的線程,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2020-11-11
  • 最新評(píng)論

    丽水市| 巴南区| 喜德县| 公安县| 凤阳县| 海阳市| 井陉县| 道孚县| 庆云县| 瑞安市| 乳源| 武清区| 大埔县| 仪征市| 米林县| 横峰县| 黔江区| 荃湾区| 扎赉特旗| 荔浦县| 石嘴山市| 密山市| 炎陵县| 盈江县| 富川| 清涧县| 麻栗坡县| 佳木斯市| 玉树县| 乐至县| 宾阳县| 旌德县| 永修县| 甘南县| 阳朔县| 二连浩特市| 龙里县| 纳雍县| 桂阳县| 台南县| 桑植县|