您的位置:首页 > 编程语言 > Python开发

读取excel文件并绘制图表[Python]

2013-06-25 17:32 459 查看
点击(此处)折叠或打开
import matplotlib.pyplot as plt

import numpy as np

import xlrd

import os

from StringIO import StringIO

if __name__ == '__main__':

data = xlrd.open_workbook('D:\\tt.xls')

plt.figure(figsize=(8,4))

plt.xlabel(u'second')

plt.ylabel(u'xxx')

x_index=1

data.sheet_names()

table = data.sheets()[0]

table = data.sheet_by_index(0)

table = data.sheet_by_name(u'Sheet1')

print("Good")

COLOR_INDEX=1

INDEX_NAME=''

## init data

nrows = table.nrows

ncols = table.ncols

print("nr=%d nc=%d \n"%(nrows,ncols))

'''

for rownum in range(table.nrows):

value = table.cell(rownum,2).value

if rownum == 0:

print("")

else:

try:

value_int = int(value)

x.append(x_index)

y.append(value_int)

# line = ax.plot(x_index,value_int,label="xx ",color="red",linewidth=2)

#plt.plot(x_index,value_int,label="xx ",color="red",linewidth=2)

print("index=%d"%x_index)

#plt.plot_date(x_index,value_int)

x_index=x_index+1

except:

print("error")

plt.plot(x,y,label="xx ",color="red",linewidth=2)

'''

for colnum in range(table.ncols):

x=[]

y=[]

for rownum in range(table.nrows):

value = table.cell(rownum,colnum).value

#print("nr=%d nc=%d value=%d \n"%(rownum,colnum,value ))

#print(value)

#print("rownum=%d colnum=%d "%(rownum,colnum))

if rownum == 0:

print("")

else:

try:

value_int = int(value)

x.append(x_index)

y.append(value_int)

#plt.plot(x_index,value_int,label=" ",color="red",linewidth=2)

#print("index=%d"%x_index)

#plt.plot_date(x_index,value_int)

x_index=x_index+1

except:

print("error")

if COLOR_INDEX == 1:

COLOR_INDEX = 0

plt.plot(x,y,color="red",linewidth=2)

else:

COLOR_INDEX =1

plt.plot(x,y,color="blue",linewidth=2)

print("==============================>")

plt.title("RTT Test")

#plt.ylim(10,2000)

plt.legend()

plt.show()

pass

阅读(123) | 评论(0) | 转发(1) |

0
上一篇:定制 bash 命令提示符

下一篇:【python】 读取Excel文件并绘制图表

相关热门文章

linux 常见服务端口

什么是shell

linux socket的bug??

linux的线程是否受到了保护?...

一个适用于windows和linux的抓...

debian7系统与ATI X2300显卡...

ubuntu sysklogd之配置文件介...

自己用的ubuntu环境搭建(一)...

linux 学习心得

用户输入操作和数据的显示...

给主人留下些什么吧!~~

评论热议
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: