1
1
2
+ using Requires
3
+
2
4
# #######################################
3
5
# # Model checks ##
4
6
# #######################################
@@ -18,70 +20,90 @@ check(m::Model) = check(create_sim(elaborate(m)))
18
20
# # Basic plotting with Gaston ##
19
21
# #######################################
20
22
21
- if " Gaston" in keys (Pkg. installed ())
22
- using Gaston
23
- end
23
+ @require Gaston begin
24
24
25
- function gplot (sm:: SimResult )
26
- N = length (sm. colnames)
27
- figure ()
28
- c = Gaston. CurveConf ()
29
- a = Gaston. AxesConf ()
30
- a. title = " "
31
- a. xlabel = " Time (s)"
32
- a. ylabel = " "
33
- Gaston. addconf (a)
34
- for plotnum = 1 : N
35
- c. legend = sm. colnames[plotnum]
36
- Gaston. addcoords (sm. y[:,1 ],sm. y[:, plotnum + 1 ],c)
25
+ function gplot (sm:: SimResult )
26
+ N = length (sm. colnames)
27
+ figure ()
28
+ c = Gaston. CurveConf ()
29
+ a = Gaston. AxesConf ()
30
+ a. title = " "
31
+ a. xlabel = " Time (s)"
32
+ a. ylabel = " "
33
+ Gaston. addconf (a)
34
+ for plotnum = 1 : N
35
+ c. legend = sm. colnames[plotnum]
36
+ Gaston. addcoords (sm. y[:,1 ],sm. y[:, plotnum + 1 ],c)
37
+ end
38
+ Gaston. llplot ()
37
39
end
38
- Gaston . llplot ( )
39
- end
40
- function gplot (sm:: SimResult , filename :: ASCIIString )
41
- Gaston. set_filename (filename )
42
- gplot (sm)
43
- Gaston . printfigure ( " pdf " )
40
+ function gplot (sm :: SimResult , filename :: ASCIIString )
41
+ Gaston . set_filename (filename)
42
+ gplot (sm)
43
+ Gaston. printfigure ( " pdf " )
44
+ end
45
+
44
46
end
45
47
46
48
47
49
# #######################################
48
50
# # Basic plotting with Winston ##
49
51
# #######################################
50
52
51
- if " Winston" in keys (Pkg. installed ())
52
- using Winston
53
- end
54
-
55
- function _wplot (sm:: SimResult )
56
- try
57
- N = length (sm. colnames)
58
- a = Winston. Table (N, 1 )
59
- for plotnum = 1 : N
60
- p = Winston. FramedPlot ()
61
- add (p, Winston. Curve (sm. y[:,1 ],sm. y[:, plotnum + 1 ]))
62
- Winston. setattr (p, " ylabel" , sm. colnames[plotnum])
63
- a[plotnum,1 ] = p
53
+ @require Winston begin
54
+
55
+ function _wplot (sm:: SimResult )
56
+ try
57
+ N = length (sm. colnames)
58
+ a = Winston. Table (N, 1 )
59
+ for plotnum = 1 : N
60
+ p = Winston. FramedPlot ()
61
+ add (p, Winston. Curve (sm. y[:,1 ],sm. y[:, plotnum + 1 ]))
62
+ Winston. setattr (p, " ylabel" , sm. colnames[plotnum])
63
+ a[plotnum,1 ] = p
64
+ end
65
+ a
66
+ end
67
+ end
68
+
69
+ function wplot (sm:: SimResult , filename:: String , args... )
70
+ try
71
+ a = _wplot (sm)
72
+ Winston. file (a, filename, args... )
73
+ a
74
+ end
75
+ end
76
+
77
+ function wplot (sm:: SimResult )
78
+ try
79
+ a = _wplot (sm)
80
+ Winston. display (a)
81
+ a
64
82
end
65
- a
66
83
end
67
84
end
68
85
69
- function wplot (sm:: SimResult , filename:: String , args... )
70
- try
71
- a = _wplot (sm)
72
- Winston. file (a, filename, args... )
73
- a
86
+ # #######################################
87
+ # # DataFrames / Gadfly integration ##
88
+ # #######################################
89
+
90
+ @require DataFrames begin
91
+
92
+ function Base. convert (:: Type{DataFrames.DataFrame} , x:: SimResult )
93
+ df = convert (DataFrames. DataFrame, x. y)
94
+ DataFrames. names! (df, [:time , map (symbol, x. colnames)])
95
+ df
74
96
end
97
+
75
98
end
76
99
77
- function wplot (sm:: SimResult )
78
- try
79
- a = _wplot (sm)
80
- Winston. display (a)
81
- a
100
+ @require Gadfly begin
101
+
102
+ function Gadfly. plot (x:: SimResult , args... )
103
+ Gadfly. plot (convert (DataFrames. DataFrame, x), args... )
82
104
end
83
- end
84
105
106
+ end
85
107
86
108
#
87
109
# @unknown
0 commit comments