Python 读取 Excel 数据绘制时域图:采样时间与输出电压
使用 Python 读取 Excel 表格数据并绘制时域图,横轴为采样时间,纵轴为输出电压。
首先,需要安装 pandas 和 matplotlib 库:
pip install pandas matplotlib
然后,可以使用以下代码来读取 Excel 数据并绘制时域图:
import pandas as pd
import matplotlib.pyplot as plt
# 读取 Excel 数据
data = pd.read_excel('your_excel_file.xlsx')
# 获取采样时间和输出电压列的数据
time = data.iloc[:, 0] # 第一列采样时间
voltage = data.iloc[:, 1:5] # 第 2 到 5 列输出电压
# 绘制时域图
plt.plot(time, voltage)
plt.xlabel('采样时间')
plt.ylabel('输出电压')
plt.legend(voltage.columns) # 添加图例,显示每列的名称
plt.show()
请将代码中的 'your_excel_file.xlsx' 替换为实际的 Excel 文件路径。这段代码会读取 Excel 文件中的第一列作为采样时间,第 2 到 5 列作为输出电压,并绘制出时域图,横轴为采样时间,纵轴为输出电压。图例会显示每列的名称。
希望这能帮助到你!如果有任何问题,请随时问我。
原文地址: https://www.cveoy.top/t/topic/bb8e 著作权归作者所有。请勿转载和采集!