# click and change color randomly import matplotlib.pyplot as plt from matplotlib.backend_bases import MouseButton import random #plt.ion() x = [1, 2, 3, 4] y = [5, 6, 7, 8] def on_click(event): if event.button is MouseButton.LEFT: print(event.xdata, event.ydata) r = random.random() g = random.random() b = random.random() plt.clf() plt.plot(x, y, 'o', color=(r, g, b)) plt.draw() plt.connect('button_press_event', on_click) plt.plot(x,y, 'ro') plt.show()