Keyboard shortcuts

/ or ⌘/Ctrl K
Find a note
j / k
Next / previous section or linked note
h / l
Collapse or go to parent / expand or enter
e or Alt-click
Read a linked note here
o
Open focused note on its own
g g / G
First / last section or linked note
g h / g a
Home / all notes
g b / g t
Backlinks / table of contents
t
Cycle System, Light, Dark
? / Esc
Show / close this reference

Search: ↑/↓ or Ctrl N/P, Enter to open. Shortcuts pause while typing.

traitlets in python [60c1678c]

, drafts, python

iPython traitlets is a multiuse library that can be used for enforcing specific trait attributes. They also can be used to facilitate quite a bit of communication between different ipywidgets, which is something I learned today.

Specifically, let's say you have a plot that takes a dataframe in a matplotlib manner, such as bqplot:

  import numpy as np
  import bqplot.pyplot as plt
  import pandas as pd
  
  
  x = pd.Series(np.linspace(-10, 10, 100)
  y = np.sin(x)
  
  fig = plt.figure()
  line = plt.plot(x=x, y=y)
  fig

Now let's say you want to have an UI that:

  • displays the entire dataframe as a filterable datagrid
  • gives you options on what to plot against
  • automatically updates the plot based on the filters in the datagrid

You can do this in shockingly few lines of Python using the ipydatagrid, bqplot, traitlets, and Jupyterwidgets.

  • Setup the jupyter dropdowns
  • Setup the datagrid
  • Setup the hook on the "transform" in the datagrid
  • Set the hook to take in the datagrid
  • Update the plot as needed
  • github.com/ipython/traitlets