import pandas as pd
# https://bl.ocks.org/mbostock/3887235原文
data = pd.DataFrame([['<5',2704659],['5-13',4499890],['14-17',2159981],
['18-24',3853788],['25-44',14106543],['45-64',8819342],['≥65',612463]],columns=('age','population'))
from nvd3 import pieChart
type = "pieChart"
chart = pieChart(name=type, color_category='category20c', height=600, width=600)
chart.set_containerheader("\n\n" + type + "\n\n")#这里是可以写html语句的
extra_serie = {"tooltip": {"y_start": "", "y_end": " men"}}
xdata = data['age']
ydata = data['population'].astype(str)
chart.add_serie(y=ydata, x=xdata, extra=extra_serie)
# 生成网页块码
chart.buildcontent()
# 显示网页块码
print(chart.htmlcontent)
# 生成html源码
chart.buildhtml()
# 保存本地
output_file = open('test_pieChart.html', 'w')
output_file.write(chart.htmlcontent)
output_file.close()
This pie chart is constructed from a CSV file storing the populations of various age groups.