栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/665974.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号