那啥…zufe的同学如果是mxw老师的数据可视化的课就不要抄这个交作业了😢博主今年也选了这门课也是作为作业备忘录用的 抄了大家都不好看😢😢😢 且我到处都有藏我的各种tag 一抄就很明显

from pyecharts import options as opts
from pyecharts.charts import Line,Page
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
import xlrd

excel=xlrd.open_workbook("us-population-by-age.xls")
sheet=excel.sheet_by_index(0)#获取工作簿
rows:list=sheet.row_values(0)#得到列名
indexyear=rows.index('')#获取列内容
listindes=sheet.col_values(indexyear)
index5=rows.index('Under 5')
listindes5=sheet.col_values(index5)
index5_19=rows.index('5 to 19')
listindes5_19=sheet.col_values(index5_19)
index20_44=rows.index('20 to 44')
listindes20_44=sheet.col_values(index20_44)
index45_64=rows.index('45 to 64')
listindes45_64=sheet.col_values(index45_64)
index65=rows.index('65+')
listindes65=sheet.col_values(index65)

c=(Line(init_opts=opts.InitOpts(width='1000px',height='600px'))
   .add_xaxis(["1860","1870","1880","1890","1900","1910","1920","1930","1940","1950","1960","1970","1980","1990","2000","2005"])#亲测如果坐标轴不加引号画不出来
   .add_yaxis("Under 5",listindes5,areastyle_opts=opts.AreaStyleOpts(opacity=0.5),stack="stack0")#填充颜色 并且stack实现堆叠
   .add_yaxis("5 to 19",listindes5_19,areastyle_opts=opts.AreaStyleOpts(opacity=0.5),stack="stack0")
   .add_yaxis("20 to 44",listindes20_44,areastyle_opts=opts.AreaStyleOpts(opacity=0.5),stack="stack0")
   .add_yaxis("45 to 64",listindes45_64,areastyle_opts=opts.AreaStyleOpts(opacity=0.5),stack="stack0")
   .add_yaxis("65+",listindes65,areastyle_opts=opts.AreaStyleOpts(opacity=0.5),stack="stack0")
   )

c.render("问题5.html")

python 堆积面积图 pyecharts堆叠面积图_python