With IPyWidgets, interactive widgets can be used to update plot parameters. Via function annotations, callback functions can react to changes in parameters and trigger a redraw.

%matplotlib inline
import pandas as pd
import numpy as np
from plotnine import *
from ipywidgets import interact

def number_of_columns(n=(4, 20, 2)):
    df = pd.DataFrame({'x': np.arange(n), 'y': np.arange(n),
      'yfit': np.arange(n) + np.tile([-.2, .2], n//2), 'cat': ['a', 'b']*(n//2)})

    return (ggplot(df)
      + geom_col(aes('x', 'y', fill='cat'))
      + geom_point(aes('x', y='yfit', color='cat'))
      + geom_path(aes('x', y='yfit', color='cat')))

This page originated from the notebook 01_interactive.ipynb which is attached to this page for safe keeping.