Plot Button

Example showing how to construct a button which will execute the construction and display of a plot.


In [ ]:
import ipywidgets
import IPython.display
import iris
import iris.plot as iplt
import matplotlib.pyplot as plt

from cube_browser import Contour, Browser, Contourf, Pcolormesh

Load cube.


In [ ]:
cube = iris.load_cube(iris.sample_data_path('GloSea4/ensemble_001.pp'))
print cube

Construct button and display it. Then define what happens when you press the button and relate the function to the button-pressing event.


In [ ]:
go_button = ipywidgets.Button(
            description='Press Me!')

IPython.display.display(go_button)

def on_button_clicked(b):
    projection = iplt.default_projection(cube)
    
    ax = plt.subplot(111, projection=projection)
    plot = Contourf(cube, ax)
    Browser([plot]).display()

go_button.on_click(on_button_clicked)