Skip to content

Commit cf6a123

Browse files
committed
Added direct plotting for Polynomial.Poly objects
1 parent 32177c0 commit cf6a123

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/Plotly.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ function plot(data::Array,options=Dict())
7979
end
8080
end
8181

82+
include("plot.jl")
83+
8284
function layout(layout_opts::Dict,meta_opts=Dict())
8385
global plotlyaccount
8486
if !isdefined(Plotly,:plotlyaccount)

src/plot.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
pkgs = keys(Pkg.installed())
2+
3+
if in("Polynomial", pkgs)
4+
using Polynomial
5+
function get_points(p::Poly, left, right, step)
6+
n::Int = (right - left) / step + 1
7+
X = Float64[0 for i in 1:n]
8+
Y = Float64[0 for i in 1:n]
9+
for i in 1:n
10+
x = step*(i-1) + left
11+
y = polyval(p, x)
12+
X[i] = x
13+
Y[i] = y
14+
end
15+
return ["x"=>X, "y"=>Y, "type"=>"scatter", "mode"=>"lines", "name"=>"$p"]
16+
end
17+
18+
function plot{T<:Number}(ps::Array{Poly{T},1}, options=Dict())
19+
opt = merge(options, ["left"=>-10, "right"=>10, "step"=>0.5])
20+
data = [get_points(p, opt["left"], opt["right"], opt["step"]) for p in ps]
21+
return plot([data], options)
22+
end
23+
24+
function plot(p::Poly, options=Dict())
25+
return plot([p], options)
26+
end
27+
end

0 commit comments

Comments
 (0)