Import the module


In [1]:
import nvd3

Prepare the data


In [2]:
x = ["One", "Two", "Three", "Four", "Five", "Six", "Seven","Eight"]
y = [29.76, 0, 32.80, 196.45, 0.19, 98.07, 13.92, 5.138]
data = [{"label": l, "value": v} for l, v in zip(x, y)]

Construct the chart


In [3]:
chart = nvd3.PieChart()
chart.x("function(d) { return d.label; }")
chart.y("function(d) { return d.value; }")
chart.showLabels(True)  # Display pie labels
chart.labelThreshold(.05)  # Configure the minimum slice size for
                           # labels to show up
chart.labelType("percent")  # Configure what type of data to show in
                            # the label. Can be "key", "value" or
                            # "percent"
chart.donut(True)  # Turn on Donut mode. Makes pie chart look tasty!
chart.donutRatio(.35)  # Configure how big you want the donut hole
                       # size to be.

Display the HTML


In [4]:
data_supplier = nvd3.StaticDataSupplier(data)
nvd3.IPythonContainer(chart, data_supplier)