pandas matplotlib 数据相关

https://pan.baidu.com/s/1vMh2EP_7A7_zBC2EZFk8eQ

Excel文档

#coding=utf-8
import pandas as pd
from pandas import Series,DataFrame
import numpy as np
import datetime
import arrow
import matplotlib.pyplot as plt

data=DataFrame(pd.read_excel(r'D:\uk30r0005\UK30R0005\uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,:]


plt.scatter(d.ix[:,3],d.ix[:,4],marker='.')
plt.scatter(d.ix[:,5],d.ix[:,6],marker='.')
plt.scatter(d.ix[:,7],d.ix[:,8],marker='.')
plt.legend(['SP1','SP2','SP3'])

plt.plot([1.05,1.29],[17100,17100],ls='--',c='b')
plt.plot([1.05,1.29],[18600,18600],ls='--',c='b')
plt.plot([1.05,1.05],[17100,18600],ls='--',c='b')
plt.plot([1.29,1.29],[17100,18600],ls='--',c='b')

plt.plot([0.97,1.23],[16320,16320],ls='--',c='orange')
plt.plot([0.97,1.23],[18060,18060],ls='--',c='orange')
plt.plot([0.97,0.97],[16320,18060],ls='--',c='orange')
plt.plot([1.23,1.23],[16320,18060],ls='--',c='orange')

plt.plot([0.92,1.18],[15660,15660],ls='--',c='g')
plt.plot([0.92,1.18],[17390,17390],ls='--',c='g')
plt.plot([0.92,0.92],[15660,17390],ls='--',c='g')
plt.plot([1.18,1.18],[15660,17390],ls='--',c='g')

plt.xlabel(u'负载电流')
plt.ylabel(u'负载转速')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['font.size']=14
plt.grid(True,alpha=0.4)

plt.xticks(np.arange(0.91,1.30,0.01),rotation=75)
plt.yticks(np.arange(15600,18700,100))
plt.title(u'UK-30R-0005 负载电流 & 转速')
plt.show()


"""
data=DataFrame(pd.read_excel(r'D:\uk30r0005\UK30R0005\uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,[1,5,6]]
d['date'] = d['date'].apply(lambda x:x.strftime('%Y-%m-%d'))   ## apply 日期转换
grouped = d.groupby(by='date',sort=False)
lists = grouped.apply(lambda x:x[x['sp2 current']>1.1])          ## 条件筛选,返回dataframe
plt.scatter(lists.ix[:,['sp2 current']],lists.ix[:,['sp2 rpm']],marker='.')
plt.show()
"""
'''
data=DataFrame(pd.read_excel(r'D:\uk30r0005\UK30R0005\uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,[1,5,6]]
sns.jointplot(d.ix[:,1],d.ix[:,2],marker='.')  ## 散点图柱状图联合图
plt.show()
'''
""" ## 散点图,SP2电流与转速
data=DataFrame(pd.read_excel(r'D:\uk30r0005\UK30R0005\uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,[1,5,6]]
d['date'] = d['date'].apply(lambda x:x.strftime('%Y-%m-%d'))   ## apply 日期转换
grouped = d.groupby(by='date',sort=False)

def pr(k):
    plt.scatter(k[k.ix[:,1]<1.1].ix[:,1],k[k.ix[:,1]<1.1].ix[:,2],marker='.',c='r')
    plt.scatter(k[k.ix[:,1]>=1.1].ix[:,1],k[k.ix[:,1]>=1.1].ix[:,2],marker='.',c='g')
grouped.apply(pr)                ## apply应用
plt.show()
"""
'''
def pr(k):
    print k[k.ix[:,1]<1.13]
grouped.apply(pr)

for g,k in grouped:
    if k.min()[1]>1.1:
        plt.scatter(k.ix[:,1],k.ix[:,2],marker='.',c='r')
    else:
        pass
##        plt.scatter(k.ix[:,1],k.ix[:,2],marker='.',c='g')
plt.scatter(d[d.ix[:,0]=='2015-07-30'].ix[:,1],d[d.ix[:,0]=='2015-07-30'].ix[:,2],marker='.',c='g')
plt.scatter(d[d.ix[:,0]=='2018-08-22'].ix[:,1],d[d.ix[:,0]=='2018-08-22'].ix[:,2],marker='.',c='g')
plt.scatter(d[d.ix[:,0]=='2015-09-15'].ix[:,1],d[d.ix[:,0]=='2015-09-15'].ix[:,2],marker='.',c='g')
plt.scatter(d[d.ix[:,0]=='2017-03-22'].ix[:,1],d[d.ix[:,0]=='2017-03-22'].ix[:,2],marker='.',c='g')
plt.show()
'''
"""
data=DataFrame(pd.read_excel(r'D:\uk30r0005\UK30R0005\uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,[1,5,6]]
grouped = d.groupby(by='date',sort=False)
for key in grouped:
    plt.scatter(key[1].ix[:,1],key[1].ix[:,2],marker='.')
plt.axhline(16320)
plt.axhline(18060)
plt.axhline(17190,c='g')
plt.axvline(0.97)
plt.axvline(1.23)
plt.axvline(1.1,c='g')
plt.show()
"""
##for k,l in grouped['sp2 current']:
##    plt.plot(l,'.')
##    arr.append(k.strftime('%Y-%m-%d'))    ##日期处理

##plt.axhline(0.97,c='red')    ##规格下限
##plt.axhline(1.1,c='green')   ##规格中值
##plt.axhline(1.23,c='red')    ##规格上限
##plt.xticks(np.arange(0,2000,100))
##plt.legend(arr,loc='best')
##plt.grid(True)
##plt.show()


'''  ## 散点图
data=DataFrame(pd.read_excel('uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,:]
grouped = d.groupby(by='date',sort=False)   ##sort=False保持原排序
plt.scatter(d.ix[:,3],d.ix[:,4],marker='.')
plt.scatter(d.ix[:,5],d.ix[:,6],marker='.')
plt.scatter(d.ix[:,7],d.ix[:,8],marker='.')
plt.axhline(16320,c='y')
plt.axhline(18060,c='y')
plt.axhline(15660,c='g')
plt.axhline(17390,c='g')
plt.axhline(17100,c='b')
plt.axhline(18610,c='b')
plt.show()
'''
'''  ## SP2 电流箱形图
data=DataFrame(pd.read_excel('uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,[1,5]]
grouped = d.groupby(by='date',sort=False)   ##sort=False保持原排序
grouped.boxplot(subplots=False,rot=75)
plt.axhline(1.1,c='green')            ##规格中值

x = grouped.groups.keys()
x.sort()
t = [date.strftime('%Y-%m-%d') for date in x]
x_range = range(1,33)
plt.xticks(x_range,t)       ## 刻度
plt.ylabel(u'SP2 电流')
plt.rcParams['font.sans-serif'] = ['SimHei']    ##中文支持
plt.show()
'''
"""
## 折线图,点阵
data=DataFrame(pd.read_excel(r'D:\uk30r0005\UK30R0005\uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,[1,5]]
grouped = d.groupby(by='date',sort=False)
arr = []
for k,l in grouped['sp2 current']:
    print l
    plt.plot(l,'.')
    arr.append(k.strftime('%Y-%m-%d'))    ##日期处理
plt.axhline(0.97,c='red')    ##规格下限
plt.axhline(1.1,c='green')   ##规格中值
plt.axhline(1.23,c='red')    ##规格上限
plt.xticks(np.arange(0,2000,100))
plt.legend(arr,loc='best')
plt.grid(True)
plt.show()
"""
'''  ##立柱图
data=DataFrame(pd.read_excel(r'D:\uk30r0005\UK30R0005\uk30r0005_2.xlsx',sheetname='Sheet2',index=None,header=0))
d = data.ix[:1564,[1,5]]
grouped = d.groupby(by='date',sort=False)  ##sort=False保持原排序
x = grouped.agg(['min','mean','max'])
x.plot(kind='bar')
plt.axhline(1.1,c='green')
plt.yticks(np.arange(0.97,1.23,0.02))
plt.show()
'''
"""  ## hist图
plt.rcParams['font.sans-serif'] = ['SimHei']    ##中文支持
plt.subplot(311)
plt.tight_layout(pad=1.5,h_pad=1.2)
plt.grid(True)
plt.title(u'SP1 负载电流(1.05~1.29A)')
plt.hist(data.ix[:1565,3],bins=20,edgecolor='black',histtype='bar')
plt.xticks(np.arange(0.90,1.32,0.02))
plt.yticks(np.linspace(0,250,11))
plt.axvline(1.05,color='red')
plt.axvline(1.29,color='red')
plt.axvline(1.17,color='green')
plt.xlabel(u'电流')

plt.subplot(312)
plt.grid(True)
plt.title(u'SP2 负载电流(0.97~1.23A)')
plt.hist(data.ix[:1565,5],bins=20,edgecolor='black',histtype='bar')
plt.xticks(np.arange(0.90,1.32,0.02))
plt.yticks(np.linspace(0,250,11))
plt.axvline(0.97,color='red')
plt.axvline(1.23,color='red')
plt.axvline(1.1,color='green')

plt.subplot(313)
plt.grid(True)
plt.title(u'SP3 负载电流(0.92~1.18A)')
plt.hist(data.ix[:1565,7],bins=20,edgecolor='black',histtype='bar')
plt.xticks(np.arange(0.90,1.32,0.02))
plt.yticks(np.linspace(0,250,11))
plt.axvline(0.92,color='red')
plt.axvline(1.18,color='red')
plt.axvline(1.05,color='green')
plt.show()
"""
'''
""" 构建legend """
d = data['order']
key = d.unique()    ##去重值'order'数组
date = data['date']
dates = [k.strftime('%Y/%m/%d') for k in date]
t = sorted(set(dates), key=dates.index)   ##去重方法
a = zip(key,t)
arr = []
for aa in a:
    arr.append(aa[0]+'  '+aa[1])

plt.grid(True)  ##SP3
plt.title(u'SP3 负载电流')
for k in key:
    current = data[data['order']==k]
    plt.plot(current.ix[:,7],'.')

plt.tight_layout(pad=1.5,h_pad=0.8)
length = 1700
y_tick = np.arange(0.90,1.20,0.02)
x_tick = np.arange(0,2100,100)
plt.xticks(x_tick)
plt.yticks(y_tick)
plt.legend(arr)
plt.ylabel(u'SP3 负载电流')
plt.rcParams['font.sans-serif'] = ['SimHei']    ##中文支持
plt.show()
'''
"""
plt.grid(True)  ##SP1
plt.title(u'SP1 负载电流')
for k in key:
    current = data[data['order']==k]
    plt.plot(current.ix[:,3],'.')

plt.tight_layout(pad=1.5,h_pad=0.8)
length = 1700
ar1 = ['1.05']*length
ar2 = ['1.29']*length
ar3 = ['1.17']*length
plt.plot(ar1,'--r')
plt.plot(ar2,'--r')
plt.plot(ar3,'--g')
y_tick = np.arange(1.04,1.30,0.02)
x_tick = np.arange(0,2100,100)
plt.xticks(x_tick)
plt.yticks(y_tick)
plt.legend(arr)
plt.ylabel(u'SP1 负载电流')
plt.rcParams['font.sans-serif'] = ['SimHei']    ##中文支持
plt.show()
"""
'''
plt.grid(True)   ##SP2
plt.title(u'SP2 负载电流')
length = 1700
for k in key:
    current = data[data['order']==k]
    plt.plot(current.ix[:,5],'.')
plt.tight_layout(pad=1.5,h_pad=0.8)
ar1 = ['0.97']*length
ar2 = ['1.23']*length
ar3 = ['1.1']*length
plt.plot(ar1,'--r')
plt.plot(ar2,'--r')
plt.plot(ar3,'--g')
y_tick = np.arange(0.96,1.24,0.02)
x_tick = np.arange(0,2100,100)
plt.xticks(x_tick)
plt.yticks(y_tick)
plt.legend(arr)
plt.ylabel(u'SP2 负载电流')
plt.rcParams['font.sans-serif'] = ['SimHei']    ##字体
##plt.rcParams['font.size']=10
plt.show()
'''

'''   ## 处理summary.csv
arr = ['SA43522A','SA43523A','SA43524A','SA43525A','SA43526A','SA43527A','SA43528A','SA43529A,','SA43529A','SA43529AA','SA44817A','SA44818A','SA44853A','SA44854A','SA45345A','SA45377A','SA45378A','SA45610A','SA45613A','SA45761A','SA45883A','SA45984A','SA46068A','SA46069A','SA46160A','SA46270A','SA46477A','SA46620A','SA46990A','SA47079A','SA47399A','SA47483A']
brr = [i for i in range(1,26)]
crr = range(25,51)
d = data[(data.ix[:,0].isin(arr)) & (data.ix[1:,1]=='Performance (3)') & (data.ix[:,2].isin(brr))]
for i in range(0,32):
    ar = [i*52+k for k in range(27,52)]
    d_values = list(d.ix[ar,4].values)
    dd_values = list(d.ix[ar,11].values)
    d_values=d_values+dd_values
    for l in d_values:
        print l

'''

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值