examples/models/structure/ModelStructureExample.ipynb
The Bokeh Structure Graph allows one to browse a model and its submodels, and to investigate its attributes.
from bokeh.models.util import generate_structure_plot
from bokeh.plotting import figure
from bokeh.io import output_notebook, show
output_notebook()
First we create a figure to analyze.
import numpy as np
X = np.linspace(-1,1,100)
Y = X + np.random.normal(size=X.shape)
f=figure(width=400,height=400)
_=f.line(x=X,y=Y,color='blue',line_width=3,alpha=.5)
_=f.line(x=X,y=X,color='red',line_width=3)
show(f)
show(generate_structure_plot(f))
We create a BokehStructureGraph object from this figure.
from bokeh.models.util import structure as st
BSG=st._BokehStructureGraph(f)
There are three resources available from the BokehStructureGraph. The first is a networkx graph that has one mode for each submodel, identified by the model id, together with the name of that submodel.
for x in BSG.graph.nodes(data=True):
print(x)
Next, there is a pandas dataframe that contains one entry for each attribute of each model, together with the value of the attribute, its type (a bokeh property) and its docstring.
BSG.property_df
BSG.property_df['doc']=BSG.property_df['doc'].str.replace('\n','')
import pandas as pd
pd.set_option('max_colwidth',None)
BSG.property_df
Finally there is a bokeh model that displays the graphical structure of the model and its submodels. Clicking on a node reveals the attributes of that model and their values.
show(BSG.model)