我有两个数据集是用不同设备以不同采样率记录的传感器值。我想将两者绘制在同一个图表中,并且它的峰值应该对齐,以便我们可以正确比较它。
我在链接中添加示例数据
基于 CSV 文件,这是一个最小的示例: 需要更多有关开始时间、结束时间和采样率的信息来改进答案。
# pip install pandas matplotlib
import pandas as pd
from matplotlib import pyplot as plt
filename = "plot.png"
"""
# CSV file Format
time,Sentea,Smartscan
0,1541.089577,1551.491018
1,1541.089379,1551.491802
2,1541.089379,1551.491018
3,1541.089455,1551.491018
4,1541.089181,1551.491802
5,1541.089295,1551.491802
...
~ 90k samples
"""
df = pd.read_csv("example.csv", index_col=0)
# Assumed for example
start_time_sentea = 16_000
start_time_smartscan = 16_000
end_time_sentea = -1
end_time_smartscan = -1
# Need more information on start time, sampling rates and end times improve
plt.plot(
df.index[start_time_sentea:end_time_sentea],
df["Sentea"][start_time_sentea:end_time_sentea],
"r",
)
plt.plot(
df.index[start_time_smartscan:end_time_smartscan],
df["Smartscan"][start_time_smartscan:end_time_smartscan],
"b",
)
plt.title("Scan Plots wrt Time")
plt.savefig(filename)
另外,请您将 CSV 公开给所有人,以便更多人可以回答。