Skip to content

Instantly share code, notes, and snippets.

@hanjinliu
Created April 28, 2022 09:38
Show Gist options
  • Save hanjinliu/ccae857b8fb49bc3cd419463737e06d3 to your computer and use it in GitHub Desktop.
Save hanjinliu/ccae857b8fb49bc3cd419463737e06d3 to your computer and use it in GitHub Desktop.
Create a layerlist-like widget for a matplotlib canvas
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