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]:
pie_chart = nvd3.PieChart()
pie_chart.x("function(d) { return d.label; }")
pie_chart.y("function(d) { return d.value; }")
pie_chart.showLabels(True)
Display the HTML
In [4]:
data_supplier = nvd3.StaticDataSupplier(data)
nvd3.IPythonContainer(pie_chart, data_supplier)