编程语言
首页 > 编程语言> > Python处理示波器CSV表格数据、微软excel格式数据

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

作者:互联网

Python处理示波器CSV文件数据、微软excel文件数据

软件环境

处理示波器导出的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()

代码运行结果展示

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

标签:12,Python,excel,plt,fontsize,CSV,data,ax1
来源: https://blog.csdn.net/qq_50632468/article/details/121981925