/
plots.jl
163 lines (117 loc) · 3.75 KB
/
plots.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
## -----
export plotif, trimplot, signchart,
plot_polar, plot_polar!,
plot_parametric, plot_parametric!,
implicit_plot, implicit_plot!,
vectorfieldplot, vectorfieldplot!,
vectorfieldplot3d, vectorfieldplot3d!,
arrow, arrow!
export newton_vis, newton_plot!, riemann_plot, riemann_plot!
##
## --------------------------------------------------
##
"""
trimplot(f, a, b, c=20; kwargs...)
Plot f over [a,b] but break graph if it exceeds c in absolute value.
"""
function trimplot end
"""
plotif(f, g, a, b)
Plot f colored depending on g ≥ 0 or not.
"""
function plotif end
"""
signchart(f, a, b)
Plot f over a,b with different color when negative.
"""
function signchart end
## --- parametric plots
"""
plot_parametric(ab, r; kwargs...)
plot_parametric!(ab, r; kwargs...)
plot_parametric(u, v, F; kwargs...)
plot_parametric!(u, v, F; kwargs...)
Make a parametric plot of a space curve or parametrized surface
The intervals to plot over are specifed using `a..b` notation, from IntervalSets
"""
function plot_parametric end
function plot_parametric! end
function plot_polar end
function plot_polar! end
## ----
function implicit_plot end
function implicit_plot! end
"""
Visualize `F(x,y,z) = c` by plotting assorted contour lines
This graphic makes slices in the `x`, `y`, and/or `z` direction of the 3-D level surface and plots them accordingly. Which slices (and their colors) are specified through a dictionary.
Examples:
```
F(x,y,z) = x^2 + y^2 + x^2
plot_implicit_surface(F, 20) # 20 slices in z direction
plot_implicit_surface(F, 20, slices=Dict(:x=>:blue, :y=>:red, :z=>:green), nlevels=6) # all 3 shown
# A heart
a,b = 1,3
F(x,y,z) = (x^2+((1+b)*y)^2+z^2-1)^3-x^2*z^3-a*y^2*z^3
plot_implicit_surface(F, xlims=-2..2,ylims=-1..1,zlims=-1..2)
```
Note: Idea [from](https://stackoverflow.com/questions/4680525/plotting-implicit-equations-in-3d).
Not exported.
"""
function plot_implicit_surface end
## ----
"""
`arrow!(p, v)`
Add the vector `v` to the plot anchored at `p`.
This would just be a call to `quiver`, but there is no 3-D version of that. As well, the syntax for quiver is a bit awkward for plotting just a single arrow. (Though efficient if plotting many).
```
using Plots
r(t) = [sin(t), cos(t), t]
rp(t) = [cos(t), -sin(t), 1]
plot(unzip(r, 0, 2pi)...)
t0 = 1
arrow!(r(t0), rp(t0))
```
"""
function arrow end
function arrow! end
function arrow3d end
function arrow3d! end
"""
vectorfieldplot(V; xlim=(-5,5), ylim=(-5,5), n=10; kwargs...)
V is a function that takes a point and returns a vector (2D dimensions), such as `V(x) = x[1]^2 + x[2]^2`.
The grid `xlim × ylim` is paritioned into (n+1) × (n+1) points. At each point, `pt`, a vector proportional to `V(pt)` is drawn.
This is written to add to an existing plot.
```
plot() # make a plot
V(x,y) = [x, y-x]
vectorfield_plot!(p, V)
p
```
"""
function vectorfieldplot end
function vectorfieldplot! end
function vectorfieldplot3d end
function vectorfieldplot3d! end
##
# visualize newtons method
"""
newton_vis(f, x0, a=Inf, b=-Inf; steps=5, kwargs...)
"""
function newton_vis end
"""
newton_plot!(f, x0; steps=5, annotate_steps::Int=0, kwargs...)
Add trace of Newton's method to plot.
* `steps`: how many steps from `x0` to illustrate
* `annotate_steps::Int`: how may steps to annotate
"""
function newton_plot! end
# visualize Riemann sum
"""
riemann_plot!(f, a, b, n; method="method", fill, kwargs...)
riemann_plot(f, a, b, n; method="method", fill, kwargs...)
Add visualization of riemann sum in a layer.
* `method`: one of `right`, `left`, `trapezoid`, `simpsons`
* `fill`: to specify fill color, something like `("green", 0.25, 0)` will fill in green with an alpha transparency.
"""
function riemann_plot! end
function riemann_plot end