Skip to content

Commit 08c10c1

Browse files
committed
Add Dymola result file example
1 parent 1e5d931 commit 08c10c1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

sdf/examples/plot_dymola_result.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sdf
2+
from sdf.plot.plot_time_series import plot_time_series
3+
import matplotlib.pyplot as plt
4+
5+
6+
# the Dymola result file
7+
filename = 'IntegerNetwork1.mat'
8+
9+
# model variables to plot
10+
variables = ['sum.y', 'product.y', 'triggeredAdd.y', 'multiSwitch1.y']
11+
12+
datasets = []
13+
14+
for variable in variables:
15+
# convert the Modelica path to an absolute SDF/HDF5 path
16+
path = '/' + variable.replace('.', '/')
17+
# read the dataset
18+
datasets.append(sdf.load(filename, path))
19+
20+
# plot the datasets
21+
figure, ax = plt.subplots()
22+
23+
for dataset, variable in zip(datasets, variables):
24+
ax.plot(dataset.scales[0].data, dataset.data, label=variable)
25+
26+
ax.legend()
27+
plt.show()

0 commit comments

Comments
 (0)