I have a graph plot and now I need a circle on it for every point where y equals zero. The graph works fine but the circle (code in the if statement) gives an error:
import numpy as np
import matplotlib.pyplot as plt
def graph(formula, x_range):
x = np.array(x_range)
y = formula(x) # <-----
#if x == y:
if y == 0:
circle2=plt.Circle((x,y),.2,color='b')
fig = plt.gcf()
fig.gca().add_artist(circle2)
plt.show()
plt.plot(x, y, 'r--')
plt.show()
graph(lambda x: (x+2) * (x-1) * (x-2), range(-3,3))