-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotter.py
68 lines (52 loc) · 2.55 KB
/
plotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import datetime
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)
class plotter:
def plot_data(self, filenames, interval) -> None:
"""
Plots data from multiple CSV files.
Args:
filenames (list): List of file paths to the CSV files.
interval (str): Time interval for resampling the data.
Returns:
None
"""
dataframes = []
for filename in filenames:
df = pd.read_csv(filename, parse_dates=['datetime'], date_parser=lambda x: pd.to_datetime(x, format="%Y-%m-%d %H:%M:%S.%f"))
df['date'] = df['datetime'].dt.date
df['time'] = df['datetime'].apply(lambda x: datetime.datetime.combine(datetime.date.today(), x.time()))
dataframes.append(df)
data = pd.concat(dataframes, ignore_index=True)
#Dato til rom:
room_codes = {
datetime.date(2023, 11, 21): 'R04',
datetime.date(2023, 11, 20): 'R03',
datetime.date(2023, 11, 24): 'FYS'}
data['room'] = data['date'].map(room_codes)
fig, axs = plt.subplots(6, figsize=(10, 20))
rooms = data['room'].unique()
for room in rooms:
data_room = data[data['room'] == room]
data_room = data_room.set_index('time').resample(interval).mean().reset_index()
axs[0].plot(data_room['time'], data_room['temp'], label=f'Temperature in {room}')
axs[1].plot(data_room['time'], data_room['pressure'], label=f'Pressure in {room}')
axs[2].plot(data_room['time'], data_room['humidity'], label=f'Humidity in {room}')
axs[3].plot(data_room['time'], data_room['gas'], label=f'Gas in {room}')
axs[4].plot(data_room['time'], data_room['lyd'], label=f'Lyd in {room}')
axs[5].plot(data_room['time'], data_room['lys'], label=f'Lys in {room}')
# Flip the y-axis
axs[4].invert_yaxis()
axs[5].invert_yaxis()
for i, label in enumerate(['Temperature (°C)', 'Pressure (hPa)', 'Humidity (%)', 'Gas', 'Lyd', 'Lys']):
axs[i].set_xlabel('Time')
axs[i].set_ylabel(label)
axs[i].set_title(f'{label} over Time')
axs[i].xaxis.set_major_formatter(mdates.DateFormatter('%H:%M'))
axs[i].legend()
plt.tight_layout()
plt.show()