Plot of Fourier Series from Part 11

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

plt.rcParams["axes.facecolor"] = "#ffff97ff"

fig = plt.figure()

fig.patch.set_facecolor("#ffff97ff")

n = 200
mystring = "y1 = np.sin(x)"
for k in range(n + 1):
    if k != 0 and k != 1:
        mystring += f"+np.sin({k}*x)/{k}"

print(f"Last index is n = {k}")
# print(mystring)

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

plt.plot(x, y1, color="blue")
plt.plot(x2, y2, color="black")
plt.text(5, 0.9, f"n = {k}", bbox={"facecolor": "red", "alpha": 0.2, "pad": 10})
plt.show()