-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_examples.py
49 lines (36 loc) · 979 Bytes
/
plot_examples.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
import os
import sys
try:
import pandas as pd
import matplotlib.pyplot as plt
path = sys.argv[1]
except ImportError:
print("You need to install pandas/matplotlib, run: pip install pandas matplotlib")
sys.exit(1)
except IndexError:
path = "." # use current directory
def load_data(file_name):
try:
df = pd.read_csv(os.path.join(path, file_name))
except FileNotFoundError:
print(f"Error: {file_name} not found.")
df = None
return df
def plot_hello_pid():
df = load_data("hello_pid.csv")
if df is None:
return
df.plot(x="t", y=["sp", "pv"])
def plot_hello_pid_array():
df = load_data("hello_pid_array.csv")
if df is None:
return
fig, ax = plt.subplots(3, 1, sharex=True)
for i in range(3):
df.plot(x="t", y=[f"sp{i+1}", f"pv{i+1}"], ax=ax[i])
def main():
plot_hello_pid()
plot_hello_pid_array()
plt.show()
if __name__ == "__main__":
main()