Relatively new to Matplotlib. I plotted a cobweb diagram and is now hoping to change the r values via arrow keys as the program is running. Tried to use "import keyboard" along with a "running loop" but it doesn't seem to work. Can someone please explain?
import matplotlib.pyplot as plt
import keyboard
from scipy import linspace
r = 3.35
x0 = 0.3
running = True
def cobweb(f, x0):
t = linspace(0, 1, 100)
l = plt.plot(t, f(t))
plt.plot(t, t)
x, y = x0, f(x0)
for _ in range(100):
fy = f(y)
plt.plot([x, y], [y, y], 'b', linewidth=1)
plt.plot([y, y], [y, fy], 'b', linewidth=1)
x, y = y, fy
plt.xlabel("X n")
plt.ylabel("X n+1")
plt.show()
plt.close()
while running:
cobweb(lambda x: r * x * (1 - x), x0)
if keyboard.is_pressed('up'):
r += 0.1
if keyboard.is_pressed('down'):
r -= 0.1
cobweb(lambda x: r * x * (1 - x), x0)

