import numpy as np
import matplotlib.pyplot as plt

def heaviside(x):
	if x >= 0:
		return 1
	else:
		return 0

def partialsum(x, N):
	S = 1/2
	for n in range(N):
		S += 2*np.sin((2*(n+1)-1)*x)/(np.pi*(2*(n+1)-1))
	return S

x = np.linspace(-5,5,1000)
y = [heaviside(t) for t in x]
y1 = [partialsum(t,100) for t in x]

fig, ax = plt.subplots()

ax.plot(x,y)
ax.plot(x,y1)

ax.grid(True)

ax.spines['left'].set_position('zero')
ax.spines['bottom'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')

plt.show()