简体   繁体   English

Python 中 x 轴上的时间和日期数据

[英]Time and date data on x-Axis in Python

ON the Raspberry PI 4, I read out a sensor (via HAT) and write the dataset into a .csv file.在 Raspberry PI 4 上,我读取了一个传感器(通过 HAT)并将数据集写入 .csv 文件。 At the same time, I write for every single value the time and date into the next column.同时,我将每个值的时间和日期写入下一列。 How do I plot these datas?我如何绘制这些数据? I want to set the x axis as the time axis, so eg.我想将 x 轴设置为时间轴,例如。 at 11:23:48 I measured 4,3 V.在 11:23:48 我测量了 4.3 V。

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from tkinter import filedialog
from tkinter import *
import sys
import warnings
if not sys.warnoptions:
    warnings.simplefilter("ignore")

root = Tk()
root.filename = filedialog.askopenfilename ( initialdir = "/home/pi", title = "Datei auswählen", filetypes = (("Comma Seperated Values (CSV)", "*.csv"), ("Alle Dateien", "*.*")) )

df = pd.read_csv(root.filename, delimiter = '\t', decimal = ',')
# pressure = df.loc [:, "Chan 0"]
temp = df.loc [:, "Chan 0 "]
df["Uhrzeit"] = df["Uhrzeit"].astype("str")
time = df.loc [:, "Uhrzeit"]
temp_echt = (52.2357*temp)-100.0001
# plt.figure (1)
# plt.plot (pressure, lw = 0.8)
plt.figure (2)
plt.ylabel ('Temperatur [°C]')
plt.plot(time,temp_echt, lw = 1)
plt.xticks (rotation = 45)
print (time)
plt.show()

Output: plot输出:绘图

So what is going on here, why does the plot look so weird?那么这里发生了什么,为什么情节看起来如此奇怪? Btw: this is the csv file: csv顺便说一句:这是 csv 文件: csv

The plot looks right to me.情节在我看来是正确的。 You have multiple same times and same Chan 0's, thats why multiple lines are over each other.您有多个相同的时间和相同的 Chan 0,这就是为什么多条线相互重叠。 It looks indeed weird.看起来确实很奇怪。 You could try to take only one Chan 0 per same time or just wait until you have more data, it should look more and more alright with the time.你可以尝试一次只取一个 Chan 0 或者等到你有更多的数据,随着时间的推移它看起来应该越来越好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM