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

python讀取excel數(shù)據(jù)繪制簡(jiǎn)單曲線圖的完整步驟記錄

 更新時(shí)間:2020年10月30日 09:01:55   作者:tianyongsen1  
這篇文章主要給大家介紹了關(guān)于python讀取excel數(shù)據(jù)繪制簡(jiǎn)單曲線圖的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

python讀寫excel文件有很多種方法:

  • 用xlrd和xlwt進(jìn)行excel讀寫
  • 用openpyxl進(jìn)行excel讀寫
  • 用pandas進(jìn)行excel讀寫

本文使用xlrd讀取excel文件(xls,sxls格式),使用xlwt向excel寫入數(shù)據(jù)

一、xlrd和xlwt的安裝

安裝很簡(jiǎn)單,windos+r調(diào)出運(yùn)行窗口,輸入cmd,進(jìn)入命令行窗口,輸入以下命令。

  • 安裝xlrd: pip install xlrd
  • 安裝xlwt: pip install xlwt

xlrd的API(application programming interface)網(wǎng)址: https://xlrd.readthedocs.io/en/latest/api.html

在這里可以看到xlrd內(nèi)的各種對(duì)象和方法

數(shù)據(jù)讀取

用xlrd讀取excle數(shù)據(jù):

  • 使用xlrd.open_wokrbook(),打開文件,得到book對(duì)象
  • book.sheet()[0]得到sheet對(duì)象
  • 基于sheet對(duì)象獲取各種信息,(往下還有cell對(duì)象)
import numpy as np
from matplotlib import pyplot as plt
import chinese
import xlrd
import xlwt
#導(dǎo)入了chinese.py來設(shè)置漢字,
chinese.set_ch()
"""讀取excel文件,API見https://xlrd.readthedocs.io/en/latest/api.html"""
filename='wind.xls'							
book_wind=xlrd.open_workbook(filename=filename)
wind_sheet1=book_wind.sheets()[0]					#這個(gè)[0]我沒看懂
#讀取第1行標(biāo)題
title=wind_sheet1.row_values(0)

#讀取第一、二、三列標(biāo)題以下的數(shù)據(jù) col_values(colx,start_row=0,end_row=none)
x=wind_sheet1.col_values(0,1)
y1=wind_sheet1.col_values(1,1)
y2=wind_sheet1.col_values(2,1)

#繪制曲線圖
line1,=plt.plot(x,y1,label='速度場(chǎng)方差')		
line1.set_dashes([2,2,10,2])			#將曲線設(shè)置為點(diǎn)劃線,set_dashes([line_space,space_space,line_space,space_space])
line2,=plt.plot(x,y2,label='流量場(chǎng)方差')
line2.set_dashes([2,2,2,2])
plt.title('方差曲線',fontsize=16)
plt.legend(loc=4)						#設(shè)置圖例位置,4表示右下角
plt.show()

總結(jié)

到此這篇關(guān)于python讀取excel數(shù)據(jù)繪制簡(jiǎn)單曲線圖的文章就介紹到這了,更多相關(guān)python讀取excel數(shù)據(jù)繪制簡(jiǎn)單曲線圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

丹棱县| 翼城县| 莲花县| 金阳县| 当雄县| 四子王旗| 龙南县| 塔河县| 壶关县| 余庆县| 神农架林区| 葫芦岛市| 大姚县| 丹寨县| 婺源县| 兴安盟| 友谊县| 新龙县| 永清县| 沈丘县| 新竹县| 新泰市| 紫阳县| 时尚| 临江市| 梁河县| 封丘县| 重庆市| 古交市| 会宁县| 常熟市| 原平市| 巴彦淖尔市| 玉溪市| 阿克苏市| 聊城市| 许昌市| 大安市| 金秀| 安顺市| 永寿县|