-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualisation.py
58 lines (46 loc) · 1.5 KB
/
visualisation.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
""" This file contains all tools to visualise data. """
from matplotlib import pyplot as plt
import pandas as pd
import files_metadata as fmd
def plot_train_file(file_name):
"""
Opens a .csv train file and plots the columns. The csv has to be the correct format in order for the plot to work.
:param file_name: file to open.
"""
df = pd.read_csv(file_name)
plot_train_dataframe(df, file_name[:-len(fmd.EXPECTED_FILE_EXTENSION)])
plt.show()
def plot_all_train_data(file_name):
"""
Plots a huge traine file by chunk over different graphs.
:param file_name: file to plot.
"""
chunk_size = 0.5*10**8
title = "chunk "
i = 0
for chunk in pd.read_csv(file_name, chunksize=chunk_size):
plot_train_dataframe(chunk, title+str(i))
i += 1
plt.show()
def plot_train_dataframe(df, title):
"""
Plots a data frame containing training data.
:param df: dataframe to plot.
:param title: title to show.
"""
# Color parameters
color1 = "red"
color2 = "blue"
# Plot first set
fig, ax1 = plt.subplots()
ax1.set_xlabel("# point")
ax1.set_ylabel(" Acoustic intensity", color=color1)
ax1.tick_params(axis='y', labelcolor=color1)
df.acoustic_data.plot(color=color1)
# Plot second set
ax2 = ax1.twinx()
ax2.set_ylabel("Time to failure [s]", color=color2)
ax2.tick_params(axis='y', labelcolor=color2)
df.time_to_failure.plot(color=color2)
plt.grid()
plt.title(title)