Skip to content

Commit c80cec0

Browse files
committed
Added recipe for plotting between two endpoints
1 parent e167507 commit c80cec0

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/PlotRecipes.jl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using RecipesBase
22

3+
34
function poly_interval(p::Poly)
45
# Find points of interest
56
zero_pts = roots(p)
@@ -10,17 +11,30 @@ function poly_interval(p::Poly)
1011
# Choose a range that shows all interesting points with some margin
1112
min_x, max_x = length(pts) > 0 ? (pts[1], pts[end]) : (-1, 1)
1213
diff = max(max_x - min_x, 1)
13-
a = min_x - diff
14-
b = max_x + diff
14+
a = min_x - diff/2
15+
b = max_x + diff/2
1516

16-
return a : diff/100 : b
17+
return a : diff/50 : b
1718
end
1819

19-
@recipe function poly_recipe(p::Poly, xs = poly_interval(p))
20+
21+
function poly_label(p::Poly)
2022
buff = IOBuffer()
2123
printpoly(buff, p)
22-
label --> String(take!(buff))
24+
String(take!(buff))
25+
end
26+
27+
28+
@recipe function poly_recipe(p::Poly, range = poly_interval(p))
29+
label --> poly_label(p)
30+
range, map(x -> polyval(p, x), range)
31+
end
32+
2333

34+
@recipe function poly_recipe(p::Poly, a, b)
35+
label --> poly_label(p)
36+
step = (b-a)/100
37+
xs = a:step:b
2438
ys = map(x -> polyval(p, x), xs)
2539
xs, ys
2640
end

0 commit comments

Comments
 (0)