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

Python处理示波器CSV表格数据、微软excel格式数据,第1张

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

Python处理示波器CSV文件数据、微软excel文件数据
    • 软件环境
    • 处理示波器导出的csv表格数据
        • csv原始数据形式
        • 处理代码
        • 代码运行结果
    • 处理Simulink导出的excel表格数据
        • 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()
代码运行结果


处理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()
代码运行结果展示


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5671242.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存