Hi all,
I am trying to plot something to follow the Squeeze Theorem. It turns out to become funny.
using Plots, LaTeXStrings
pyplot(fmt=:svg)
function pitick(start, stop, denom; mode=:text)
a = Int(cld(start, π/denom))
b = Int(fld(stop, π/denom))
tick = range(a*π/denom, b*π/denom; step=π/denom)
ticklabel = piticklabel.((a:b) .// denom, Val(mode))
tick, ticklabel
end
function piticklabel(x::Rational, ::Val{:text})
iszero(x) && return "0"
S = x < 0 ? "-" : ""
n, d = abs(numerator(x)), denominator(x)
N = n == 1 ? "" : repr(n)
d == 1 && return S * N * "π"
S * N * "π/" * repr(d)
end
function piticklabel(x::Rational, ::Val{:latex})
iszero(x) && return L"0"
S = x < 0 ? "-" : ""
n, d = abs(numerator(x)), denominator(x)
N = n == 1 ? "" : repr(n)
d == 1 && return L"%$S%$N\pi"
L"%$S\frac{%$N\pi}{%$d}"
end
a, b = -2π, 2π
#plot(sin, a, b; xtick=pitick(a, b, 4), label="y = sin t", size=(720, 250))
#plot(cos, a, b; xtick=pitick(a, b, 4), label="y = cos t", size=(720, 250))
f(x) = 1 + sin(x+π)
g(x) = -1 + sin(x+π)
h(x) = sin(4x+π)
plot(f, a, b; xtick=pitick(a, b, 4; mode=:latex), label="f", size=(720, 360), tickfontsize=10)
plot!(g, a, b; xtick=pitick(a, b, 4; mode=:latex), label="g", size=(720, 360), tickfontsize=10)
plot!(h, a, b; xtick=pitick(a, b, 4; mode=:latex), label="h", size=(720, 360), tickfontsize=10)
The result that I want is like this:
what should I do to make it works?
The f
and h
functions are the sin
that is translated toward y-axis, but how to draw the g that follow the movement of the outside functions?
Like putting Bollinger Bands indicator toward the securities chart.