Plot of Dirichlet Kernel from Part 18

import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np



fig = plt.figure()

fig.patch.set_facecolor('#ffff97ff')
plt.rcParams['axes.facecolor'] = '#ffff97ff'

pi = np.pi
n = 11
mystring = f"y1 = np.sin(({n}+1/2)*x)/(np.sin(x/2))"

x = np.arange(-1*pi, pi, 0.01)
x2 = np.arange(-1*pi, pi, 0.01)
y2 = np.cos(2*x2)*0
exec(mystring)

plt.plot(x, y1, color='purple')
plt.plot(x2, y2, color='gray')
plt.title(f"n = {n}")
plt.show()

plot