Plot Type Selector

Example showing how to construct a dropdown widget that can be used to select a plot type. Here a dictionary must be used for the plot type options.


In [ ]:
import ipywidgets
import IPython.display
import iris
import numpy as np

import iris.quickplot as iplt
import matplotlib.pyplot as plt

Load cube.


In [ ]:
cube = iris.load_cube(iris.sample_data_path('A1B.2098.pp'))
print cube

Compose and sort a dictionary of plot-types and then construct widget to present them, along with a default option. Display the widget using the IPython display call.


In [ ]:
plot_type_dict = {'contour': iplt.contour, 'contourf': iplt.contourf, 'pcolor': iplt.pcolor, 'outline': iplt.outline,
                  'pcolormesh': iplt.pcolormesh, 'plot': iplt.plot, 'points': iplt.points}

plot_types = plot_type_dict.keys()
sorted(plot_types)

im = ipywidgets.Dropdown(
    description='Plot-type:',
    options=plot_types,
    value='contour')

IPython.display.display(im)

Print selected widget value for clarity.


In [ ]:
print im.value