Skip to content

Commit c97007c

Browse files
committed
Merge pull request #2 from snotskie/master
Continuing to make Plotly.plot play well with other packages: TimeSeries and WAV
2 parents 69f5087 + a95f6c7 commit c97007c

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ That last line is what the REPL prints out,
3535
as a Firefox tab opens with the plot.
3636
You can also just call `plot` by itself, and you'll get a String that's the url of your chart.
3737

38+
## Style and Layout
39+
julia> Plotly.style(["line"=>["color"=>"rgb(255,0,0)","width"=>10]])
40+
41+
julia> Plotly.layout(["layout"=>["title"=>"Time Wasted"]])
42+
3843
## Plot Functions and Polynomials
3944
julia> Plotly.plot(abs)
4045
julia> Plotly.plot([sqrt, log], ["left"=>10, "right"=>20, "step"=>0.1])
@@ -48,13 +53,17 @@ the square root and logarithm functions, both from 10 to 20 at increments of 0.1
4853
julia> Plotly.plot(3x^3 + 2x^2 - x + 1)
4954

5055
If you have the Polynomial package installed, you can plot them directly the same way as math functions.
51-
52-
## Style and Layout
53-
julia> Plotly.style(["line"=>["color"=>"rgb(255,0,0)","width"=>10]])
5456

55-
julia> Plotly.layout(["layout"=>["title"=>"Time Wasted"]])
56-
57-
57+
## Plot TimeSeries
58+
julia> using TimeSeries
59+
julia> d = [date(2012,5,29):date(2013,5,29)]
60+
julia> t = TimeArray(d, rand(length(d),2), ["foo","bar"])
61+
julia> Plotly.plot(t)
5862

63+
If you have the TimeSeries package installed, you can plot them directly by passing a TimeArray argument.
5964

65+
## Plot WAV Files
66+
julia> using WAV
67+
julia> Plotly.plot(wavread("filename.wav"))
6068

69+
If you have the WAV package installed, you can plot WAV files by passing a call to the wavread function.

src/plot.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function plot(f::Function, options=Dict())
2323
end
2424

2525
if Pkg.installed("Polynomial") !== nothing
26-
using Polynomial
26+
import Polynomial: Poly, polyval
2727

2828
function plot{T<:Number}(ps::Array{Poly{T},1}, options=Dict())
2929
data = [get_points(x->polyval(p,x), merge(["name"=>"$p"], options)) for p in ps]
@@ -33,4 +33,27 @@ if Pkg.installed("Polynomial") !== nothing
3333
function plot(p::Poly, options=Dict())
3434
return plot([p], options)
3535
end
36+
end
37+
38+
if Pkg.installed("TimeSeries") !== nothing
39+
import TimeSeries: TimeArray, timestamp, values, colnames
40+
41+
function plot(ts::TimeArray, options=Dict())
42+
data = [
43+
["x"=>map(t->"$t", timestamp(ts[col])), "y"=>values(ts[col]), "type"=>"scatter", "mode"=>"lines", "name"=>col]
44+
for col in colnames(ts)
45+
]
46+
return plot([data], options)
47+
end
48+
end
49+
50+
if Pkg.installed("WAV") !== nothing
51+
function plot{T<:Number,U<:Number,V<:Number}(wav::(Array{T,2},U,V,UnionType), options=Dict())
52+
opt = merge(["layout"=>["xaxis"=>["title"=>"seconds","dtick"=>1,"tick0"=>0,"autotick"=>false]]], options)
53+
w, Fs = wav
54+
X = [f/Fs for f in 1.0:length(w)]
55+
Y = [round(y,8) for y in w]
56+
data = [["x"=>X, "y"=>Y, "type"=>"scatter", "mode"=>"lines", "name"=>"WAV data"]]
57+
return plot([data], opt)
58+
end
3659
end

0 commit comments

Comments
 (0)