Wenn ich das Beispiel von der Matplotlibseite nehme, funktioniert alles. Die Checkbox wird angeklickt und der Graph wird angezeigt und umgekehrt. Hier der Code.
Code: Alles auswählen
mport numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import CheckButtons
t = np.arange(0.0, 2.0, 0.01)
s0 = np.sin(2*np.pi*t)
s1 = np.sin(4*np.pi*t)
s2 = np.sin(6*np.pi*t)
fig, ax = plt.subplots()
l0, = ax.plot(t, s0, visible=False, lw=2)
l1, = ax.plot(t, s1, lw=2)
l2, = ax.plot(t, s2, lw=2)
plt.subplots_adjust(left=0.2)
rax = plt.axes([0.05, 0.4, 0.1, 0.15])
check = CheckButtons(rax, ['2 Hz', '4 Hz', '6 Hz'], [False, True, True])
def func(label):
if label == '2 Hz':
l0.set_visible(not l0.get_visible())
elif label == '4 Hz':
l1.set_visible(not l1.get_visible())
elif label == '6 Hz':
l2.set_visible(not l2.get_visible())
plt.draw()
check.on_clicked(func)
plt.show()
Code: Alles auswählen
from matplotlib.widgets import CheckButtons
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = np.sin(2*np.pi*t)
s1 = np.sin(4*np.pi*t)
ax = plt.subplot(111)
l0, = ax.plot(s, t, visible=True, lw=2)
l1, = ax.plot(t, s1, lw=2)
rax = plt.axes( [.05, .4, .1, .15] )
check = CheckButtons(rax, ('Graph1', 'Graph2'), (True, True))
def fnx(checkbox_label):
if checkbox_label == 'Graph1':
l0.set_visible(not l0.get_visible())
elif checkbox_label == 'Graph2':
l1.set_visible(not l1.get_visible())
check.on_clicked(fnx)
plt.show()
Danke im Voraus