Possible to hide FigureWidget in Jupyter notebook programmatically?

Consider this code:

import plotly.graph_objs as go
import numpy as np
from ipywidgets import widgets
from IPython.display import display

XMAX = 10
xs = np.linspace(0, XMAX, 100)

fig = go.FigureWidget( layout=go.Layout() )

def TransferFunction(inval):
    return inval**2

# transfer function plot
fig.add_trace(go.Scatter(x=xs, y=TransferFunction(xs),
                    mode='lines',
                    name='Transfer'))
fig.data[0].line.color="blue"

widgets.VBox([fig])

In a Jupyter notebook, it generates a graph like this:

Is it possible - and if so, how - to hide this figure altogether (say, have the encompassing box as HTML/CSS display:none)? There is a show() method for FigureWidget, but I cannot see a hide() method …

Got it - the thing is, while FigureWidget does not have any properties related to visible/visibility/display - the Layout object does; and not the go.Layout object (which gets applied to the go.FigureWidget class/object) – but the ipywidgets.Layout, which gets applied to the encompassing VBox! Of course, it was not confusing at all having two classes called Layout :slight_smile:

So, all we need to do, is to keep a reference to the ipywidgets.Layout, and then we can manipulate its .display property, as so:

import plotly.graph_objs as go
import numpy as np
#from ipywidgets import interact, interactive
import ipywidgets
from ipywidgets import widgets
from IPython.display import display

XMAX = 10
xs = np.linspace(0, XMAX, 100)

fig = go.FigureWidget( layout=go.Layout() )

def TransferFunction(inval):
    return inval**2

# transfer function plot
fig.add_trace(go.Scatter(x=xs, y=TransferFunction(xs),
                    mode='lines',
                    name='Transfer'))
fig.data[0].line.color="blue"

ipywLayout = ipywidgets.Layout(border='solid 2px green')
#ipywLayout.display='none' # uncomment this, run cell again - then the graph/figure disappears
widgets.VBox([fig], layout=ipywLayout)

Of course, it would be great to know if there is a more proper way to do this…