python(添加时间轴组件):玫瑰图分月展示2020年1-3月汽车销量(pyecharts)
转自https://zhuanlan.zhihu.com/p/144874116
案例中数据表格结构如下:
代码及演示:
from pyecharts import options as opts
from pyecharts.charts import Pie, Timeline
import pandas as pd
from pyecharts.globals import ThemeType
df_pie = pd.read_excel("D:\\01\\会Excel的隔壁老王\\Excel报表\\20200531-python(添加时间轴组件):玫瑰图展示2020年1-3月汽车销量\\20200531-python(添加时间轴组件):玫瑰图展示2020年1-3月汽车销量 - 副本.xlsx")
tl = Timeline(init_opts=opts.InitOpts(width="800px", height="500px",theme = ThemeType.CHALK ))
for i in ["一季度","1月","2月","3月"]:
pie = (
Pie(init_opts=opts.InitOpts(width="800px", height="500px",theme = ThemeType.CHALK ))
.add(
" ",
df_pie[["型号",i]].values,
rosetype="radius",
radius=["30%", "60%"],
center=["50%", "50%"],
is_clockwise=1,
label_opts=opts.LabelOpts(is_show=1),
)
.set_global_opts(title_opts=opts.TitleOpts("2020年{}汽车销量(微信公众号:会Excel的隔壁老王)".format(i),pos_bottom = "88%", pos_right = "17%"))
.set_series_opts(label_opts = opts.LabelOpts(formatter="{b}:{c}\n占比:{d}%") )
)
tl.add(pie, "{}".format(i))
tl.add_schema(
is_inverse = 0,
pos_bottom = "0%"
)
tl.render_notebook()