python读取excel画数据曲线
生活随笔
收集整理的這篇文章主要介紹了
python读取excel画数据曲线
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
部分數據
test.xlsx 兩列,第一列為x, 第二列為y
代碼:
# coding=utf-8import matplotlib matplotlib.use('TkAgg') import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import sys import xlrddef read_xlrd(excelFile):x=[]y=[]data = xlrd.open_workbook(excelFile)table = data.sheet_by_index(0)#print("rows:", table.nrows);for rowNum in range(table.nrows):rowVale = table.row_values(rowNum)x.append(rowVale[0])y.append(rowVale[1])#print(rowVale[0], rowVale[1])#for colNum in range(table.ncols):#print(rowVale[colNum])return x,yx,y = read_xlrd(sys.argv[1])plt.plot(x, y) plt.grid(True) ##增加格點 plt.show()執行
python3 show.py ./test.xlsx
注意這里python版本是3
另外matplotlib會有不顯示的問題,所以要加matplotlib.use(‘TkAgg’), 不然matplotlib默認的后端無法顯示。
示例圖
作者:帥得不敢出門
總結
以上是生活随笔為你收集整理的python读取excel画数据曲线的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python 高级编程笔记之类别
- 下一篇: python pandas 条件求和_p