# y= abs(x-2*np.floor((x+1)/2 )
import numpy as np
import matplotlib.pyplot as plt
import math
x = np.linspace(-4.5,4.5,100)
y = abs(x-2*np.floor((x+1)/2))
plt.plot(x,y,color="green",linewidth=3)
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
plt.show()
Out[16]: