python pandas&&matplotlib

#  经过验证:  pandas中 无法直接读xls的文件
import pandas as pd
import matplotlib.pyplot as plt
#f= open(r'C:\Users\tiger\Desktop\python\python教程\data\data5/coordinates of curling.csv','r',encoding='utf-8')
#data = pd.read_csv(r'C:\Users\tiger\Desktop\python\python教程\data\data5/coordinates of curling.csv') # r 表示其中的字符全部都是字符串
data = pd.read_excel(r'C:\Users\tiger\Desktop\python\python教程\data\data5\coordinates_of_curling.xlsx')
data2 = pd.read_excel(r'C:\Users\tiger\Desktop\python\python教程\data\data5\attitude_of_curling.xlsx')
pos_x = data.iloc[:,2] # iloc 表示的是按照行列来查找相应的数据。 而loc表示按照key来查找数据
pos_y = data.iloc[:,3]
print(data2)
time = data2.iloc[1:,0] # 表示从第一行开始,第0列
yaw = data2.iloc[1:,1]
pitch = data2.iloc[1:,2]
row = data2.iloc[1:,3]
accx = data2.iloc[1:,4]
accy = data2.iloc[1:,5]
accz = data2.iloc[1:,6]
gyrox = data2.iloc[1:,7]
gyroy = data2.iloc[1:,8]
gyroz = data2.iloc[1:,9]
#print(guroz)
plt.subplot(221) # sbuplot 中221表示二行二列中的第一个
plt.title('coordinate of curling') # 表示 表格的title
plt.xlabel('x_axis') # 横坐标 的名字
plt.ylabel('y_axis') # 纵坐标的名字
plt.plot(pos_x,pos_y)


plt.subplot(222)
plt.title('Rotation of curling')
plt.xlabel('time')
plt.ylabel('Angle of rotation')
p1,=plt.plot(time,yaw)
p2,=plt.plot(time,pitch)
p3,=plt.plot(time,row) # 注意要加入逗号。
plt.legend(handles = [p1,p2,p3],labels =['yaw','pitch','row'],loc = 'best') # legend是每一个图线的名字 local = ‘best’表示 自己选择最好的位置
plt.subplot(223)
plt.title('Acceleration of curling')
plt.xlabel('time')
plt.ylabel('Acceleration')
p1,=plt.plot(time,accx)
p2,=plt.plot(time,accy)
p3,=plt.plot(time,accz)
plt.legend(handles=[p1,p2,p3],labels =('accx','accy','accz'),loc ='best')
plt.subplot(224)
plt.title('Angular velocity of curling')
plt.xlabel('time')
plt.ylabel('Angular velocity')
p1,=plt.plot(time,gyrox)
p2,=plt.plot(time,gyroy)
p3,=plt.plot(time,gyroz)
plt.legend(handles=[p1,p2,p3],labels =('gyrox','gyroy','gyroz'),loc ='best')

plt.show()

# for line in f :
# print (line )
#print(data)

# 感谢一下几位同学的帮助

http://blog.csdn.net/quincuntial/article/details/70947363
https://www.2cto.com/kf/201407/317115.html
https://i.cnblogs.com/EditPosts.aspx?opt=1

转载于:https://www.cnblogs.com/dotiger/p/8299312.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值