ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2021-12-16 19:30:22  阅读:255  来源: 互联网

标签:12 Python excel plt fontsize CSV data ax1


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()

代码运行结果

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

处理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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有