from sympy import *
from spb import *
import param
from bokeh.models.formatters import PrintfTickFormatter

x, T, n, m = symbols("x, T, n, m")
sawtooth = frac(x / T)
# Fourier Series of a sawtooth wave
fs = S(1) / 2 - (1 / pi) * Sum(sin(2 * n * pi * x / T) / n, (n, 1, m))

formatter = PrintfTickFormatter(format="%.3f")
plot(
    (sawtooth, (x, 0, 10), "f", {"line_dash": "dotted"}),
    (fs, (x, 0, 10), "approx"),
    params = {
        T: (4, 0, 10, 80, formatter),
        m: param.Integer(4, bounds=(1, None), label="Sum up to n ")
    },
    xlabel = "x",
    ylabel = "y",
    backend = BB,
    use_latex = False
)