Is there a matplotlib built-in way to display checkboxes along the legend, allowing the user to select/unselect some of the 3 curves in a realtime live plotting? (I currently refresh data with set_ydata, but I can change this if needed)
import numpy as np
import matplotlib.pyplot as plt
import threading, time
def visualization_thread():
fig = plt.figure()
ax = fig.add_subplot(111)
l1, *_ = ax.plot(y1, color='r', label="1")
l2, *_ = ax.plot(y2, color='g', label="2")
l3, *_ = ax.plot(y3, color='b', label="3")
fig.show()
fig.legend()
fig.canvas.flush_events()
while True:
l1.set_ydata(y1)
l2.set_ydata(y2)
l3.set_ydata(y3)
fig.canvas.draw_idle()
fig.canvas.flush_events()
plt.pause(0.020)
def data_thread():
global y1, y2, y3
while True:
y1 = np.random.rand(100)
y2 = np.random.rand(100)
y3 = np.random.rand(100)
time.sleep(0.020)
threading.Thread(target=data_thread).start()
threading.Thread(target=visualization_thread).start()
