数据
代码:
import pandas as pd import pyecharts.options as opts from pyecharts.charts import Bar from pyecharts.globals import ThemeType data=pd.read_csv('presidential_approval_rate.csv') y4=data['political_issue'].size datax=['支持','反对','不发表意见'] for i in range(y4): issue=data.loc[i,'political_issue'] y1=data.loc[i,['support','oppose','no_opinion']] y1=list(y1) print(issue) print(y1) bar=(Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) .add_xaxis(datax) .add_yaxis(issue,y1,stack=True) .set_series_opts( #set_series_opts系列配置设置 label_opts=opts.LabelOpts(position="inside", color="black", font_size=13,font_style="italic", font_weight='normal',font_family='SimSun', formatter="{c}")) .set_global_opts(title_opts=opts.TitleOpts(title="柱状图数据堆叠")) ) bar.render("比例中的柱状数据堆叠图2.html")
运行结果:输出的issue、y1和图