代码调用
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
import copy
字体设置
#################代码及说明
font1 = {'family' : 'SimSun','weight' : 'normal','size': 15,}
#SimSun宋体 Times New Roman新罗马字体 定义一个font字典来存储字体格式 设置字体的格式、大小
df=pd.read_csv('56008/Diesel_LFWSRXSJ1K1E56008_2020-04-22_394.csv')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
###这两句也相当于设置字体,但在尝试过程中发现没什么用
plt.plot(df['EBP_VAR_W'],label='进气压力输出值')
plt.xlabel('采样点(时间间隔1秒)',fontdict=font1)
plt.ylabel('进气压力(MPa)',fontdict=font1)
plt.legend(prop=font1,loc='upper right')
##字体大小及legend位置
plt.show()
转速条形图绘制
#转速条形图绘制(600-650.......转速区间)(600-650)
series_1 = np.array([4317,1029,778,820,1058,1722,2569,4103,5368,6473,7698,9117,11287,11587,13949,16789,20112,21101,19904,14563,8141,4401]) #500-1000扭矩总数
series_2 = np.array([16693,2089,2173,2406,3514,5662,10567,19480,30357,43625,49530,43632,34354,24688,15230,8549,4819,2229,1042,504,236,83]) #500-1000扭矩总数
series_3 = np.array([11989,1166,1137,1563,2168,3467,6448,9314,12806,15074,16057,17202,17750,17400,10351,6449,3477,1486,665,329,168,50]) #500-1000扭矩总数
series_4 = np.array([8339,3103,2834,3907,5163,6534,7746,8069,7265,6354,5192,4204,3520,2546,1874,1412,1147,730,439,282,201,114]) #500-1000扭矩总数
series_5 = np.array([86157,4848,4673,5467,7615,13527,27863,51532,84173,116214,134134,108275,119261,13923,4332,1298,350,61,39,13,15,9]) #500-1000扭矩总数
series_6 = np.array([12316,1057,866,849,999,1285,1576,1862,2111,3627,8862,19064,23651,20994,20828,19572,15248,9372,4498,1565,512,176]) #500-1000扭矩总数
series_7 = np.array([19318,2113,1725,1890,2453,3471,5703,9680,20654,31561,53092,74563,55309,47612,41121,33696,24371,18096,12627,6779,4154,2466]) #500-1000扭矩总数
series_8= np.array([24092,2980,3446,4563,6740,10452,16350,22707,28523,34301,37212,33318,28216,22639,15335,10699,6558,3651,3585,2495,650,230]) #500-1000扭矩总数
font1 = {'family' : 'SimSun','weight' : 'normal','size' : 15,}
labels = ['625','675','725','775','825','875','925','975','1025','1075','1125','1175','1225','1275','1325','1375','1425','1475','1525','1575','1625','1675']
max=140000
################################################################################八个一起
#t = np.arange(0,22)
#plt.figure(figsize=(10,150))
#plt.rcParams['font.sans-serif'] = ['SISong']
#plt.rcParams['axes.unicode_minus'] = False
##ax1 = plt.subplot(811)
##plt.bar(t, series_1,label='P1904-17')
##plt.legend(prop=font1,loc='upper right')
##plt.xlim(-1.2,22)
# # plt.ylim(0, max)
# # # plt.xticks(range(len(labels)),labels)
# # plt.setp(ax1.get_xticklabels(),fontsize=10)
# # plt.ylabel('总数据量/个',fontdict=font1,position=(625,1.1),rotation=0)
#
# # share x only
# ax2 = plt.subplot(711)
# plt.bar(t, series_2,label='56008')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
# plt.ylim(0, max)
# plt.ylabel('总数据量/个',fontdict=font1,position=(625,1.1),rotation=0)
# # make these tick labels invisible
#
#
# # share x and y
# ax3 = plt.subplot(712, sharey=ax2)
# plt.bar(t, series_3,label='56006')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
#
# ax4 = plt.subplot(713, sharex=ax2, sharey=ax2)
# plt.bar(t, series_4,label='51412')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
#
# ax5 = plt.subplot(714)
# plt.bar(t, series_5,label='50600')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
#
#
# # share x only
# ax6 = plt.subplot(715, sharey=ax2)
# plt.bar(t, series_6,label='50380')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
# # make these tick labels invisible
#
#
# # share x and y
# ax7 = plt.subplot(716, sharey=ax2)
# plt.bar(t, series_7,label='50379')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
#
# ax8 = plt.subplot(717, sharey=ax2)
# plt.bar(t, series_8,label='50246')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
#
#
# plt.xticks(range(len(labels)),labels,rotation=30)
# plt.xlabel('转速区间中心点(r/min)',fontdict=font1)
# plt.show()
转速饼状图绘制
#绘制饼状图
##################(600-650)
# # Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels ='800-900r/min','900-950r/min','950-1000r/min', '1000-1050r/min', '1050-1100r/min', \
'1100-1150r/min','1150-1200r/min','1200-1250r/min','1250-1300r/min','1300-1350r/min','1350-1400r/min',\
'1400-1500r/min'
sizes = [75830,78822,126747,191257,257229,311777,309375,293348,161389,123020,98464,132808]
sizes = [75830,78822,126747,191257,257229,311777,309375,293348,161389,123020,98464,76082,56726] explode = ( 0, 0, 0,0,0,0,0,0,0,0,0,0) # only "explode" the 2nd slice (i.e. 'Hogs')
colors=['lightyellow','lightcyan','paleturquoise','mediumturquoise','c','darkslategrey','teal','c','mediumturquoise','paleturquoise','lightcyan','lightyellow',]
fig1, ax1 = plt.subplots()
patches,l_text,p_text=ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',colors=colors,
shadow=True, startangle=90,pctdistance=0.9)
for t in l_text:
t.set_size(10)
for t in p_text:
t.set_size(10)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()
扭矩条形图绘制
# # ######################################################################扭矩条形图绘制
the_ans=pd.read_csv('the_ans.csv')
series_1=the_ans.loc[:,'A']
series_2=the_ans.loc[:,'B']
series_3=the_ans.loc[:,'C']
series_4=the_ans.loc[:,'D']
series_5=the_ans.loc[:,'E']
series_6=the_ans.loc[:,'F']
series_7=the_ans.loc[:,'G']
print(series_1)
font1 = {'family' : 'SimSun',
'weight' : 'normal',
'size' : 15,}
labels=np.arange(550,2550,100)
labels = ['550','650','750','775','825','875','925','975','1025','1075','1125','1175','1225','1275','1325','1375','1425','1475','1525','1575','1625','1675']
# t = np.arange(0,20)
# plt.figure(figsize=(10,150))
# #
# plt.rcParams['font.sans-serif'] = ['SISong']
# plt.rcParams['axes.unicode_minus'] = False
# #
# max=130000
#
#
# ax1 = plt.subplot(711)
# plt.bar(t, series_1,label='50379')
# plt.legend(prop=font1,loc='upper right')
# plt.xlim(-1.2,22)
# plt.ylim(0,max )
# # plt.xticks(range(len(labels)),labels)
# plt.setp(ax1.get_xticklabels(),fontsize=10)
# plt.ylabel('总数据量/个',fontdict=font1,position=(625,1.1),rotation=0)
# #
# # # share x only
# ax2 = plt.subplot(712,sharey=ax1)
# plt.bar(t, series_2,label='50246')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
# # # make these tick labels invisible
# #
# #
# # share x and y
# ax3 = plt.subplot(713, sharey=ax1)
# plt.bar(t, series_3,label='50380')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
# #
# ax4 = plt.subplot(714, sharex=ax1, sharey=ax1)
# plt.bar(t, series_4,label='50600')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
# #
# ax5 = plt.subplot(715, sharey=ax1)
# plt.bar(t, series_5,label='51412')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
# #
#
# ax6 = plt.subplot(716, sharey=ax1)
# plt.bar(t, series_6,label='56006')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
#
#
# ax8 = plt.subplot(717, sharey=ax1)
# plt.bar(t, series_7,label='56008')
# plt.legend(prop=font1,loc='upper right')
# plt.xticks([])
# plt.xlim(-1.2,22)
# #
# #
# plt.xticks(range(len(labels)),labels,rotation=30)
# plt.xlabel('扭矩区间中心点(r/min)',fontdict=font1)
# plt.show()
扭矩饼状图绘制
# # Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels ='500-600Nm','600-700Nm','700-800Nm', '800-900Nm', '900-1000Nm', '1000-1100r/min','1100-1200r/min','1200-1300r/min','1300-1400r/min','1400-1500r/min','1500-1600r/min',\
# '1600-1700r/min','1700-1800r/min','1800-1900r/min','1900-2000r/min'
sizes = [75830,78822,126747,191257,257229,311777,309375,293348,161389,123020,98464,76082,56726]
# sizes=[79926,84369,86084,176171,123938,121255,113811,108250,99100,88964,75463,64465,52778,50093,62016]
#
# # explode = ( 0, 0, 0,0,0,0,0,0,0,0,0,0,0) # only "explode" the 2nd slice (i.e. 'Hogs')
#
colors=['lightcyan','lightcyan','paleturquoise','darkslategrey','teal','mediumturquoise','c','c','mediumturquoise','paleturquoise','lightcyan','lightyellow',
# 'lightyellow','lightyellow','lightyellow',]
# fig1, ax1 = plt.subplots()
#
# patches,l_text,p_text=ax1.pie(sizes, labels=labels, autopct='%1.1f%%',colors=colors,
# shadow=True, startangle=90,pctdistance=0.9)
#
# for t in l_text:
# t.set_size(10)
# for t in p_text:
# t.set_size(10)
#
# ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
#
# plt.show()
绘制某一天所有的状态参数
#####################################################################绘制某一天的所有状态参数
df=pd.read_csv('51412/Diesel_LFWSRXSJ1K1F51412_2020-03-02_382.csv')
selet_X=pd.read_csv('selectx_1.csv')
k=0
for i in selet_X.iloc[:,0]:
y=df[i]
x=np.arange(len(y))
plt.scatter(x,y,label=selet_X.iloc[k,1],s=1)
plt.legend(prop=font1,loc='upper right')
plt.savefig("E:\变量图/51412_03_04\状态参数/{}".format(i)) # 保存图片
plt.clf() # 更新画布
k+=1
画三维图
#################################################################################################画三维图
# from mpl_toolkits.mplot3d import Axes3D
selectx = pd.read_csv('selectX.csv')
k=0
for i in selectx.iloc[:,0]:
df_1 = pd.read_csv('51412/Diesel_LFWSRXSJ1K1F51412_2020-03-09_382.csv')
df_2=pd.read_csv('51412/23400Diesel_LFWSRXSJ1K1F51412_2020-03-06_382.csv')
df_3=pd.read_csv('51412/Diesel_LFWSRXSJ1K1F51412_2020-03-08_382.csv')
df_4=pd.read_csv('51412/23400Diesel_LFWSRXSJ1K1F51412_2020-03-05_382.csv')
df_5=pd.read_csv('51412/23400Diesel_LFWSRXSJ1K1F51412_2020-03-04_382.csv')
# df_1=pd.read_csv('50600/00C10A00Diesel_LFWSRXSJ8K1F50600_2020-04-06_927.csv')
# df_2=pd.read_csv('50600/00C10A00Diesel_LFWSRXSJ8K1F50600_2020-04-08_927.csv')
# df_3=pd.read_csv('50600/00C10A00Diesel_LFWSRXSJ8K1F50600_2020-04-11_927.csv')
# df_4=pd.read_csv('50600/0004FD00Diesel_LFWSRXSJ8K1F50600_2020-04-04_927.csv')
# df_5=pd.read_csv('50600/0004FD00Diesel_LFWSRXSJ8K1F50600_2020-04-21_927.csv')
# df_6=pd.read_csv('50600/Diesel_LFWSRXSJ8K1F50600_2020-04-20_927.csv')
# df_7=pd.read_csv('50600/Diesel_LFWSRXSJ8K1F50600_2020-04-19_927.csv')
ax = plt.figure().add_subplot(111, projection='3d')
#
# df_1=df_1[(df_1['EESP_VAR_N_W']>=1000)&(df_1['EESP_VAR_N_W']<=1250)&(df_1['TQMOD_VAR_TRQ_ACT_W'] >= 800) & (df_1['TQMOD_VAR_TRQ_ACT_W'] <= 1200)]
# df_2=df_2[(df_2['EESP_VAR_N_W']>=1000)&(df_2['EESP_VAR_N_W']<=1250)&(df_2['TQMOD_VAR_TRQ_ACT_W'] >= 800) & (df_2['TQMOD_VAR_TRQ_ACT_W'] <= 1200)]
# # df_3 = df_3[(df_3['EESP_VAR_N_W'] >= 1000) & (df_3['EESP_VAR_N_W'] <= 1250)&(df_3['TQMOD_VAR_TRQ_ACT_W'] >= 800) & (df_3['TQMOD_VAR_TRQ_ACT_W'] <= 1200)]
# df_4 = df_4[
# (df_4['EESP_VAR_N_W'] >= 1000) & (df_4['EESP_VAR_N_W'] <= 1250) & (df_4['TQMOD_VAR_TRQ_ACT_W'] >= 800) & (
# df_4['TQMOD_VAR_TRQ_ACT_W'] <= 1200)]
# df_1.loc[:,'EBP_VAR_W']=df_1.loc[:,'EBP_VAR_W']+20
x,y=np.meshgrid(df_1['EESP_VAR_N_W'],df_1['TQMOD_VAR_TRQ_ACT_W'])
ax.scatter(df_1['EESP_VAR_N_W'],df_1['TQMOD_VAR_TRQ_ACT_W'],df_1[i],label=selectx.iloc[k,1]+'G',s=1,alpha=0.3)
ax.scatter(df_2['EESP_VAR_N_W'],df_2['TQMOD_VAR_TRQ_ACT_W'],df_2[i],label='bad',s=1,alpha=0.3)
# ax.scatter(df_1_PN['EESP_VAR_N_W'],df_1_PN['TQMOD_VAR_TRQ_ACT_W'],df_1_PN[i],label='good',s=40)
# ax.scatter(df_2_PN['EESP_VAR_N_W'],df_2_PN['TQMOD_VAR_TRQ_ACT_W'],df_2_PN[i],label='bad',s=40)
# ax.scatter(df_1['EESP_VAR_N_W'], df_1['TQMOD_VAR_TRQ_ACT_W'], df_1[i], label='good')
ax.scatter(df_3['EESP_VAR_N_W'],df_3['TQMOD_VAR_TRQ_ACT_W'],df_3[i],s=1,alpha=0.3,label='G')
ax.scatter(df_4['EESP_VAR_N_W'],df_4['TQMOD_VAR_TRQ_ACT_W'],df_4[i],s=1,alpha=0.3,label='bad')
ax.scatter(df_5['EESP_VAR_N_W'], df_5['TQMOD_VAR_TRQ_ACT_W'], df_5[i], s=1,alpha=0.3,label='BAD')
# ax.scatter(df_6['EESP_VAR_N_W'], df_6['TQMOD_VAR_TRQ_ACT_W'], df_6[i], label='g')
ax.set_zlabel('Z') # 坐标轴
ax.set_ylabel('Y')
ax.set_xlabel('X')
plt.legend(prop=font1,loc='upper right')
# plt.savefig("E:/figures/56008_4_22滤波对比/{}.png".format(i+'筛选后'))
# plt.clf()
plt.show()
k+=1