Created
April 28, 2022 09:38
-
-
Save hanjinliu/ccae857b8fb49bc3cd419463737e06d3 to your computer and use it in GitHub Desktop.
Create a layerlist-like widget for a matplotlib canvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from magicclass import magicclass, field | |
from magicclass.widgets import Figure | |
from magicgui.widgets import CheckBox, Container | |
@magicclass | |
class A: | |
plt = field(Figure) | |
cbs = field(Container) | |
def add_plot(self): | |
line, *_ = self.plt.ax.plot(np.random.random(100)) | |
cb = CheckBox(value=True) | |
@cb.changed.connect | |
def _toggle(v): | |
line.set_visible(v) | |
self.plt.draw() | |
self.cbs.append(cb) | |
self.plt.draw() | |
ui = A() | |
ui.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment