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 = 100
mystring = "y1 = 1/2"
for k in range(n):
if k%2 == 1:
mystring += f"+np.sin({k}*x)*(-2)/(np.pi*{k})"
print(f"Last index is k = {k}")
x = np.arange(-1*np.pi, np.pi, 0.01)
x2 = np.arange(-1*np.pi, 0, 0.01)
x3 = np.arange(0*np.pi, np.pi, 0.01)
exec(mystring)
y2 = 1+np.cos(2*x2)*0
y3 = np.cos(2*x3)*0
plt.plot(x, y1, color='blue')
plt.plot(x2, y2, color='black')
plt.plot(x3, y3, color='black')
plt.show()