当前位置:   article > 正文

Python处理示波器CSV表格数据、微软excel格式数据_示波器的数据表格

示波器的数据表格

软件环境

  • Sublimtext 3——Version 3.1.1 (便携版)
  • Sublimtext选择python编译环境
  • anaconda——Version 4.10.3。可通过CMD窗口安装缺失依赖库xxx,安装指令pip install xxx

处理示波器导出的csv表格数据

csv原始数据形式

在这里插入图片描述

处理代码
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data = pd.read_csv('tek0017_HFSI_load.csv',skiprows=20,nrows=1000000)

# print(data.to_string())
print('The result of print is \n', data)

x = data['TIME']
y = data['CH1']

fig = plt.figure()

# control the settings of graph, such as font、 fontsize , and etc
plt.rc('font',family='Times New Roman')
plt.rcParams['xtick.direction']='out'	# or 'in'
plt.rcParams['ytick.direction']='out'
plt.rcParams['axes.autolimit_mode'] = 'round_numbers'

plt.plot(x,y,linewidth = 1,label='ia')

plt.xlabel('Time (s)', fontsize=12)
plt.ylabel('ia (A)', fontsize=12)
plt.xticks(fontsize = 12)
plt.yticks(fontsize = 12)
plt.xlim(-0.5,0.5)
plt.ylim(-3,3)
plt.grid(True, linestyle='--')
plt.legend(loc='upper center', bbox_to_anchor=(0.15, 0.99),shadow=False)

# control the number of ticks
# plt.locator_params('x',nbins = 5)
# plt.locator_params('y',nbins = 7)

# reset the coordinate scale
plt.xticks([-0.5, -0.25, 0, 0.25, 0.5],
  ['0', '0.25', '0.5', '0.75', '1'])

## insert the subgraph
left, bottom, width, height = 0.65,0.6,0.2,0.2
ax1 = fig.add_axes([left, bottom, width, height])
ax1.plot(x,y,'r')
# ax1.set_xlabel('Time (s)')
ax1.set_xlim(0,0.2)
ax1.set_ylim(-2.5,2.5)
# control the fontsize of ticks of subgraph
# ##https://github.com/matplotlib/matplotlib/issues/12318
for tick in ax1.xaxis.get_majorticklabels():  # example for xaxis
    tick.set_fontsize(12) 
for tick in ax1.yaxis.get_majorticklabels():  # example for xaxis
    tick.set_fontsize(12) 

ax1.grid(True, linestyle='--')
# ax1.locator_params(tight=True, nbins=2)

plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
代码运行结果

在这里插入图片描述
在这里插入图片描述

处理Simulink导出的excel表格数据

excel原始数据形式

在这里插入图片描述

数据处理代码
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data = pd.read_excel('excel_simulink.xlsx')

print(data)

AA = data['time']
BB = data['HRP']

plt.figure()

plt.rc('font',family='Times New Roman')
plt.rcParams['xtick.direction']='in'
plt.rcParams['ytick.direction']='in'
plt.rcParams['axes.autolimit_mode'] = 'round_numbers'

plt.plot(AA,BB,linewidth = 1,label='HRP')

plt.xlabel('Time (s)', fontsize=12)
plt.ylabel('HRP (rad)', fontsize=12)
plt.xticks(fontsize = 12)
plt.yticks(fontsize = 12)
plt.xlim(0,0.01)
plt.ylim(0,0.3)
plt.grid(True, linestyle='--')
plt.legend(loc='upper center', bbox_to_anchor=(0.88, 0.95),shadow=False)

plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
代码运行结果展示

在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/490527
推荐阅读
相关标签
  

闽ICP备14008679号