I am trying to plot temperature data points according to their time recording.
t = ['2021-12-11T0:6:15', '2021-12-11T7:15', '2021-12-11T8:15', '2021-12-11T9:15', '2021-12-11T10:15']
temp = [33.6, 33.6, 33.6, 33.6, 33.6]
Note: as you have mentioned t
is represented without hour
, the reason is that temp
been collected in hour:second
.
t
is a string representing the date and time in ISO 8601 format (ref: datetime.datetime.isoformat()) and temp
is a floating number. The plot should be in a way that t
in x-axis
(represented as hour:min) and temp
in y-axis
(represented in celcius). I want to keep the variables as lists and plot a graph without using Pandas but PyQtGraph library.
I tried the following:
from PySide6.QtWidgets import (
QApplication,
QMainWindow
)
import pyqtgraph as pg # import PyQtGraph after Qt
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.graphWidget = pg.PlotWidget()
self.setCentralWidget(self.graphWidget)
t = # declared above
temp = # declared above
# plot data: time, temp values
self.graphWidget.plot(time, temp)
# Always start by initializing Qt (only once per application)
app = QApplication([])
window = MainWindow()
## Display the widget as a new window
window.show()
## Start the Qt event loop
app.exec_()
After running the above code, I got a traceback:
numpy.core._exceptions._UFuncNoLoopError: ufunc 'fmin' did not contain a loop with signature matching types (dtype('<U18'), dtype('<U18')) -> None
I know that there is a problem with t
since its values are str
which they should be same type as of temp
(note: temp
values should always stay float
). I am not sure how to fix it.
I am using PySide6 and PyQtGraph, where Python is the language used. For this, I also tried to just plot the two variables using matplotlib
library. I did the following:
import numpy as np
import matplotlib.pyplot as plt
x, y = t, temp
plt.plot(x, y, label='temperature fluctuation')
plt.xlabel('time (hour:min)')
plt.ylabel('temperature (C)')
plt.legend(loc='lower right')