11
2+ using Requires
3+
24# #######################################
35# # Model checks ##
46# #######################################
@@ -18,70 +20,90 @@ check(m::Model) = check(create_sim(elaborate(m)))
1820# # Basic plotting with Gaston ##
1921# #######################################
2022
21- if " Gaston" in keys (Pkg. installed ())
22- using Gaston
23- end
23+ @require Gaston begin
2424
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 ()
3739 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+
4446end
4547
4648
4749# #######################################
4850# # Basic plotting with Winston ##
4951# #######################################
5052
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
6482 end
65- a
6683 end
6784end
6885
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
7496 end
97+
7598end
7699
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... )
82104 end
83- end
84105
106+ end
85107
86108#
87109# @unknown
0 commit comments