Repository navigation
Expand file tree
/
Copy pathplot_time_series.py
More file actions
67 lines (48 loc) · 1.62 KB
/
Copy pathplot_time_series.py
File metadata and controls
67 lines (48 loc) · 1.62 KB
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
import sdf
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pylab as pylab
def plot_time_series(filename, datasets):
params = {
# 'legend.fontsize': 'medium',
"figure.figsize": (10, 8),
"axes.labelsize": "small",
# 'axes.titlesize': 'medium',
"xtick.labelsize": "small",
"ytick.labelsize": "small",
}
pylab.rcParams.update(params)
figure, axes = plt.subplots(len(datasets), sharex=True)
# figure = plt.figure()
figure.patch.set_facecolor("white")
for ax, path in zip(axes, datasets):
dataset = sdf.load(filename, path)
scale = dataset.scales[0]
y = dataset.data
x = scale.data if scale is not None else range(len(y))
# ax = figure.add_subplot(len(datasets), 1, i + 1)
ax.plot(x, y, "b")
ax.grid(b=True, which="both", color="0.8", linestyle="-")
ax.set_xlim([np.nanmin(x), np.nanmax(x)])
ylabel = path
if dataset.unit is not None:
ylabel += " / %s" % dataset.unit
ax.set_ylabel(ylabel)
ax.margins(y=0.05)
# x-axis label
if scale is not None:
xlabel = scale.name
if scale.unit is not None:
xlabel += " / %s" % scale.unit
else:
xlabel = "Index"
ax.set_xlabel(xlabel)
figure.tight_layout()
plt.show()
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("filename")
parser.add_argument("datasets", nargs="+")
args = parser.parse_args()
plot_time_series(filename=args.filename, datasets=args.datasets)