11function get_points (f:: Function , options= Dict ())
2- default = { " left" => - 10 , " right" => 10 , " step" => 0.5 , " name" => " $f " , " type" => " scatter" , " mode" => " lines" }
2+ default = Dict ( " left" => - 10 , " right" => 10 , " step" => 0.5 , " name" => " $f " , " type" => " scatter" , " mode" => " lines" )
33 opt = merge (default, options)
44 n:: Int = (opt[" right" ] - opt[" left" ]) / opt[" step" ] + 1
55 X = Float64[0 for i in 1 : n]
@@ -12,31 +12,31 @@ function get_points(f::Function, options=Dict())
1212 end
1313
1414 if opt[" type" ] == " histogram"
15- return { " x" => Y, " type" => opt[" type" ], " mode" => opt[" mode" ], " name" => opt[" name" ]}
15+ return Dict ( " x" => Y, " type" => opt[" type" ], " mode" => opt[" mode" ], " name" => opt[" name" ])
1616 elseif opt[" type" ] == " box"
17- return { " y" => Y, " type" => opt[" type" ], " mode" => opt[" mode" ], " name" => opt[" name" ]}
17+ return Dict ( " y" => Y, " type" => opt[" type" ], " mode" => opt[" mode" ], " name" => opt[" name" ])
1818 else
19- return { " x" => X, " y" => Y, " type" => opt[" type" ], " mode" => opt[" mode" ], " name" => opt[" name" ]}
19+ return Dict ( " x" => X, " y" => Y, " type" => opt[" type" ], " mode" => opt[" mode" ], " name" => opt[" name" ])
2020 end
2121end
2222
23- scatter (f:: Array , options= Dict ()) = merge ({ " type" => " scatter" ," mode" => " markers" , " x" => [1 : length (f)], " y" => f} , options)
24- line (f:: Array , options= Dict ()) = merge ({ " type" => " scatter" ," mode" => " lines" , " x" => [1 : length (f)], " y" => f} , options)
25- box (f:: Array , options= Dict ()) = merge ({ " type" => " box" , " x" => [1 : length (f)], " y" => f} , options)
26- histogram (f:: Array , options= Dict ()) = merge ({ " type" => " histogram" , " y" => [1 : length (f)], " x" => f} , options)
27- bar (f:: Array , options= Dict ()) = merge ({ " type" => " bar" , " x" => [1 : length (f)], " y" => f} , options)
23+ scatter (f:: Array , options= Dict ()) = merge (Dict ( " type" => " scatter" ," mode" => " markers" , " x" => [1 : length (f)], " y" => f) , options)
24+ line (f:: Array , options= Dict ()) = merge (Dict ( " type" => " scatter" ," mode" => " lines" , " x" => [1 : length (f)], " y" => f) , options)
25+ box (f:: Array , options= Dict ()) = merge (Dict ( " type" => " box" , " x" => [1 : length (f)], " y" => f) , options)
26+ histogram (f:: Array , options= Dict ()) = merge (Dict ( " type" => " histogram" , " y" => [1 : length (f)], " x" => f) , options)
27+ bar (f:: Array , options= Dict ()) = merge (Dict ( " type" => " bar" , " x" => [1 : length (f)], " y" => f) , options)
2828
29- scatter (f:: Dict , options= Dict ()) = merge ({ " type" => " scatter" ," mode" => " markers" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]} , options)
30- line (f:: Dict , options= Dict ()) = merge ({ " type" => " scatter" ," mode" => " lines" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]} , options)
31- box (f:: Dict , options= Dict ()) = merge ({ " type" => " box" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]} , options)
32- histogram (f:: Dict , options= Dict ()) = merge ({ " type" => " histogram" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]} , options)
33- bar (f:: Dict , options= Dict ()) = merge ({ " type" => " bar" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]} , options)
29+ scatter (f:: Dict , options= Dict ()) = merge (Dict ( " type" => " scatter" ," mode" => " markers" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]) , options)
30+ line (f:: Dict , options= Dict ()) = merge (Dict ( " type" => " scatter" ," mode" => " lines" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]) , options)
31+ box (f:: Dict , options= Dict ()) = merge (Dict ( " type" => " box" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]) , options)
32+ histogram (f:: Dict , options= Dict ()) = merge (Dict ( " type" => " histogram" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]) , options)
33+ bar (f:: Dict , options= Dict ()) = merge (Dict ( " type" => " bar" , " x" => [k for k in sort (collect (keys (f)))], " y" => [f[k] for k in sort (collect (keys (f)))]) , options)
3434
35- scatter (f:: Function , options= Dict ()) = get_points (f, merge ({ " type" => " scatter" ," mode" => " markers" } , options))
36- line (f:: Function , options= Dict ()) = get_points (f, merge ({ " type" => " scatter" ," mode" => " lines" } , options))
37- box (f:: Function , options= Dict ()) = get_points (f, merge ({ " type" => " box" } , options))
38- histogram (f:: Function , options= Dict ()) = get_points (f, merge ({ " type" => " histogram" } , options))
39- bar (f:: Function , options= Dict ()) = get_points (f, merge ({ " type" => " bar" } , options))
35+ scatter (f:: Function , options= Dict ()) = get_points (f, merge (Dict ( " type" => " scatter" ," mode" => " markers" ) , options))
36+ line (f:: Function , options= Dict ()) = get_points (f, merge (Dict ( " type" => " scatter" ," mode" => " lines" ) , options))
37+ box (f:: Function , options= Dict ()) = get_points (f, merge (Dict ( " type" => " box" ) , options))
38+ histogram (f:: Function , options= Dict ()) = get_points (f, merge (Dict ( " type" => " histogram" ) , options))
39+ bar (f:: Function , options= Dict ()) = get_points (f, merge (Dict ( " type" => " bar" ) , options))
4040
4141plot (f:: Function , options= Dict ()) = plot ([line (f, options)])
4242plot (fs:: Array{Function,1} , options= Dict ()) = plot ([line (f, options) for f in fs])
@@ -51,7 +51,7 @@ if Pkg.installed("Polynomial") !== nothing
5151 bar (p:: Poly , options= Dict ()) = bar (x-> polyval (p,x), options)
5252
5353 function plot {T<:Number} (ps:: Array{Poly{T},1} , options= Dict ())
54- data = [get_points (x-> polyval (p,x), merge ({ " name" => " $p " } , options)) for p in ps]
54+ data = [get_points (x-> polyval (p,x), merge (Dict ( " name" => " $p " ) , options)) for p in ps]
5555 return plot ([data], options)
5656 end
5757
@@ -64,14 +64,14 @@ if Pkg.installed("TimeSeries") !== nothing
6464 import TimeSeries: TimeArray, timestamp, values, colnames
6565
6666 scatter (ts:: TimeArray , options= Dict ()) = [
67- { " x" => map (t-> " $t " , timestamp (ts[col])), " y" => values (ts[col]), " type" => " scatter" , " mode" => " markers" , " name" => col}
67+ Dict ( " x" => map (t-> " $t " , timestamp (ts[col])), " y" => values (ts[col]), " type" => " scatter" , " mode" => " markers" , " name" => col)
6868 for col in colnames (ts)
6969 ]
7070
71- line (ts:: TimeArray , options= Dict ()) = [merge (x,{ " type" => " line" ," mode" => " lines" } ) for x in scatter (ts)]
72- box (ts:: TimeArray , options= Dict ()) = [merge (x,{ " type" => " box" } ) for x in scatter (ts)]
73- histogram (ts:: TimeArray , options= Dict ()) = [merge (x,{ " type" => " histogram" } ) for x in scatter (ts)]
74- bar (ts:: TimeArray , options= Dict ()) = [merge (x,{ " type" => " bar" } ) for x in scatter (ts)]
71+ line (ts:: TimeArray , options= Dict ()) = [merge (x,Dict ( " type" => " line" ," mode" => " lines" ) ) for x in scatter (ts)]
72+ box (ts:: TimeArray , options= Dict ()) = [merge (x,Dict ( " type" => " box" ) ) for x in scatter (ts)]
73+ histogram (ts:: TimeArray , options= Dict ()) = [merge (x,Dict ( " type" => " histogram" ) ) for x in scatter (ts)]
74+ bar (ts:: TimeArray , options= Dict ()) = [merge (x,Dict ( " type" => " bar" ) ) for x in scatter (ts)]
7575 plot (ts:: TimeArray , options= Dict ()) = plot ([line (ts)], options)
7676end
7777
@@ -80,30 +80,30 @@ if Pkg.installed("WAV") !== nothing
8080 w, Fs = wav
8181 X = [f/ Fs for f in 1.0 : length (w)]
8282 Y = [round (y,8 ) for y in w]
83- return { " x" => X, " y" => Y, " type" => " scatter" , " mode" => " lines" , " name" => " WAV data" }
83+ return Dict ( " x" => X, " y" => Y, " type" => " scatter" , " mode" => " lines" , " name" => " WAV data" )
8484 end
8585
86- scatter {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ()) = merge (line (wav),{ " type" => " scatter" ," mode" => " markers" } )
87- box {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ()) = merge (line (wav),{ " type" => " box" } )
88- histogram {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ()) = merge (line (wav),{ " type" => " histogram" } )
89- bar {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ()) = merge (line (wav),{ " type" => " bar" } )
86+ scatter {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ()) = merge (line (wav),Dict ( " type" => " scatter" ," mode" => " markers" ) )
87+ box {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ()) = merge (line (wav),Dict ( " type" => " box" ) )
88+ histogram {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ()) = merge (line (wav),Dict ( " type" => " histogram" ) )
89+ bar {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ()) = merge (line (wav),Dict ( " type" => " bar" ) )
9090
9191 function plot {T<:Number,U<:Number,V<:Number} (wav:: (Array{T,2},U,V,UnionType) , options= Dict ())
92- opt = merge ({ " layout" => { " xaxis" => { " title" => " seconds" ," dtick" => 1 ," tick0" => 0 ," autotick" => false }}} , options)
92+ opt = merge (Dict ( " layout" => Dict ( " xaxis" => Dict ( " title" => " seconds" ," dtick" => 1 ," tick0" => 0 ," autotick" => false ))) , options)
9393 return plot ([line (wav)], opt)
9494 end
9595end
9696
9797if Pkg. installed (" DataFrames" ) != = nothing
9898 import DataFrames: DataFrame
9999
100- scatter (df:: DataFrame , options= Dict ()) = get_points (df, merge ({ " type" => " scatter" ," mode" => " markers" } , options))
101- line (df:: DataFrame , options= Dict ()) = get_points (df, merge ({ " type" => " scatter" ," mode" => " lines" } , options))
102- box (df:: DataFrame , options= Dict ()) = get_points (df, merge ({ " type" => " box" } , options))
103- histogram (df:: DataFrame , options= Dict ()) = get_points (df, merge ({ " type" => " histogram" } , options))
104- bar (df:: DataFrame , options= Dict ()) = get_points (df, merge ({ " type" => " bar" } , options))
100+ scatter (df:: DataFrame , options= Dict ()) = get_points (df, merge (Dict ( " type" => " scatter" ," mode" => " markers" ) , options))
101+ line (df:: DataFrame , options= Dict ()) = get_points (df, merge (Dict ( " type" => " scatter" ," mode" => " lines" ) , options))
102+ box (df:: DataFrame , options= Dict ()) = get_points (df, merge (Dict ( " type" => " box" ) , options))
103+ histogram (df:: DataFrame , options= Dict ()) = get_points (df, merge (Dict ( " type" => " histogram" ) , options))
104+ bar (df:: DataFrame , options= Dict ()) = get_points (df, merge (Dict ( " type" => " bar" ) , options))
105105 function get_points (df:: DataFrame , options= Dict ())
106- default = { " type" => " scatter" , " mode" => " lines" }
106+ default = Dict ( " type" => " scatter" , " mode" => " lines" )
107107 opt = merge (default, options)
108108 for axis in [" xs" , " ys" ]
109109 if haskey (opt, axis) && typeof (opt[axis]) <: Symbol
@@ -114,27 +114,27 @@ if Pkg.installed("DataFrames") !== nothing
114114 if haskey (opt, " xs" ) && haskey (opt, " ys" )
115115 if length (opt[" xs" ]) == length (opt[" ys" ])
116116 return [
117- { " x" => df[opt[" xs" ][i]], " y" => df[opt[" ys" ][i]], " type" => opt[" type" ], " mode" => opt[" mode" ]}
117+ Dict ( " x" => df[opt[" xs" ][i]], " y" => df[opt[" ys" ][i]], " type" => opt[" type" ], " mode" => opt[" mode" ])
118118 for i in 1 : length (opt[" xs" ])
119119 ]
120120 else
121121 return [
122- { " x" => df[x], " y" => df[y], " type" => opt[" type" ], " mode" => opt[" mode" ]}
122+ Dict ( " x" => df[x], " y" => df[y], " type" => opt[" type" ], " mode" => opt[" mode" ])
123123 for x in opt[" xs" ], y in opt[" ys" ]
124124 ]
125125 end
126126 elseif haskey (opt, " xs" )
127127 return [
128- { " x" => df[x], " type" => opt[" type" ], " mode" => opt[" mode" ]}
128+ Dict ( " x" => df[x], " type" => opt[" type" ], " mode" => opt[" mode" ])
129129 for x in opt[" xs" ]
130130 ]
131131 elseif haskey (opt, " ys" )
132132 return [
133- { " y" => df[y], " type" => opt[" type" ], " mode" => opt[" mode" ]}
133+ Dict ( " y" => df[y], " type" => opt[" type" ], " mode" => opt[" mode" ])
134134 for y in opt[" ys" ]
135135 ]
136136 else
137- return { " error" => " Please set the xs and/or ys options." }
137+ return Dict ( " error" => " Please set the xs and/or ys options." )
138138 end
139139 end
140140
@@ -146,7 +146,7 @@ if Pkg.installed("DataFrames") !== nothing
146146 elseif haskey (options, " ys" )
147147 return plot ([box (df)], options)
148148 else
149- return { " error" => " Please set the xs and/or ys options." }
149+ return Dict ( " error" => " Please set the xs and/or ys options." )
150150 end
151151 end
152- end
152+ end
0 commit comments