def TimelinePie(data_nums: dict): ''' 我自己选的八个出版社的年出版量对比\n :param data_nums: 字典,键为年份,值是列表,存放各出版社的出版数量 :return: 不存在 ''' global dir_to_save attr = ['机械工业出版社', '人民邮电出版社', '电子工业出版社', '清华大学出版社', '人民文学出版社', '上海译文出版社', '生活·读书·新知三联书店', '广西师范大学出版社'] tl = Timeline() for i in tqdm(range(2002, 2015)): pie = ( Pie() .add( "", [list(z) for z in zip(attr, data_nums[i])], rosetype="radius", radius=["30%", "55%"], ) .set_global_opts(title_opts=opts.TitleOpts("8个出版社的{}年出版量对比".format(i), pos_top='15%') ) ) tl.add(pie, "{}年".format(i)) tl.add_schema(is_auto_play=True, play_interval=1000) tl.render(dir_to_save + "TypicalPublishers_timeline_pie.html") print("Successfully drew TypicalPublishers_timeline_pie")
def print_gauge(): timeline3 = Timeline(init_opts=opts.InitOpts(bg_color="black")) for i in range(len(Grid)): b = batteryenergy[i] / 900 * 100 gauge0 = (Gauge(init_opts=opts.InitOpts(bg_color="black")).add( series_name="grid", data_pair=[["", round(b, 1)]], max_=100, min_=0, start_angle=210, split_number=5, end_angle=-30, axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(color=[( 0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=20)), detail_label_opts=opts.LabelOpts(formatter="{value}%", ), radius="80%").set_global_opts( legend_opts=opts.LegendOpts(is_show=False), tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"), title_opts=opts.TitleOpts( "Percentage of battery energy at time {}".format(time[i]), title_textstyle_opts=opts.TextStyleOpts(color="white")))) timeline3.add(gauge0, "{}年".format(i)).add_schema( is_timeline_show=True).add_schema(play_interval=2000, is_auto_play=True, is_timeline_show=False) timeline3.render("C:/Users/suqi/Desktop/allcode/gaugenew.html")
def dong_scatter(data, info='', path0=''): from pyecharts import options as opts from pyecharts.commons.utils import JsCode from pyecharts.charts import Scatter, Timeline # endlist = ['canshu', 'celue_name', '预测_s_Time', '未来end_3', '最终预测值1', 'hg最终预测值1'] data['aim'] = data['canshu'] + data['celue_name'] data.rename(columns={ 'hg最终预测值1': '预测值', '未来end_3': '未来=月终收益', '预测_s_Time': 's_Time' }, inplace=True) print(data.columns) print(data.tail()) title = '动态图' df = data # data['预测值'] = data['预测值'].apply(lambda x: int(x)) min_pre = min(data['预测值'].values.tolist()) max_pre = max(data['预测值'].values.tolist()) # df['未来=月终收益']=df['未来=月终收益'].apply(lambda x: int(x)) # df['预测值']=df['预测值'].apply(lambda x: int(x)) df['s_Time'] = pd.to_datetime( df['s_Time']) #.apply(lambda x:x.strftime(format="%Y-%m-%d")) df.sort_values(by=['s_Time'], ascending=True, inplace=True) tl = Timeline() timelist = list(set(df['s_Time'].tolist())) print(list(set(df['s_Time'].tolist()))) sorted(timelist) # df_date = [time.strftime('%Y-%m-%d',time.localtime(i/1000000000) ) for i in timelist] # print(df_date) for k, i in enumerate(sorted(timelist)): # print(k,i) xdata = df.loc[df['s_Time'] == i, '预测值'].values.tolist() ydata = df.loc[df['s_Time'] == i, ['未来=月终收益', '预测值']].values.tolist() # print(ydata) Scatter0 = (Scatter().add_xaxis(xdata).add_yaxis( '未来=月终收益', ydata, label_opts=opts.LabelOpts(is_show=False) ).set_series_opts().set_global_opts( xaxis_opts=opts.AxisOpts( name='预测值:', type_="value", axistick_opts=opts.AxisTickOpts(is_show=True)), yaxis_opts=opts.AxisOpts( name='真实值:', type_="value", axistick_opts=opts.AxisTickOpts(is_show=True)), title_opts=opts.TitleOpts(title=f"{title}==:{i}月份的数据"), tooltip_opts=opts.TooltipOpts(formatter=JsCode( "function (params) { return '真实:'+params.value[1] +' == 预测:'+ params.value[2];}" )), visualmap_opts=opts.VisualMapOpts(min_=min_pre, max_=max_pre), )) tl.add(Scatter0, "{}月".format(i)) tl.render(path0 + f"{info}.html") print(path0 + f"{info}.html")
def charts(): fp = open('./oldData.txt', 'r') # Timeline timeline = Timeline(init_opts=opts.InitOpts( width="1660px", height="708px", )) # 48 bar charts for i in range(48): X, Y, Color = getSta(fp) # y-axle with color y = [] for j in range(22): y.append( opts.BarItem( name=X[j], value=Y[j], itemstyle_opts=opts.ItemStyleOpts(color=Color[j]))) # single bar chart bar = ( Bar().add_xaxis(X).add_yaxis( "Youbike 使用率", y).reversal_axis().set_global_opts( title_opts=opts.TitleOpts( title="南港區Youbike的一天", pos_left="center", ), legend_opts=opts.LegendOpts(pos_left="left"), graphic_opts=[ opts.GraphicGroup( # add a block graphic_item=opts.GraphicItem(left="80%", top="80%"), children=[ opts.GraphicText( # add text into the block graphic_item=opts.GraphicItem( left="center", top="center", # z=100 ), graphic_textstyle_opts=opts. GraphicTextStyleOpts( text="{}".format(invTime[i]), font="48px Verdana", ), ) ]) ]).set_series_opts( # number showed at right of the bar label_opts=opts.LabelOpts(position="right", color="#333"))) timeline.add(bar, "") # add single bar chart into timeline timeline.add_schema(play_interval=1000, is_loop_play=True) # play settings # export into HTML timeline.render("YoubikeUsingRate.html") fp.close()
def render_map(date_list, cy_name_list, ncov_data) -> Map: tl = Timeline() tl.add_schema(is_auto_play=True, play_interval=60, is_loop_play=False, width=700) for date_str in date_list: map_ = (Map(init_opts=opts.InitOpts( bg_color='rgba(255,250,205,0.2)', width='1000px', height='600px', page_title='page', theme=ThemeType.MACARONS)).add( "全球疫情变化", [list(z) for z in zip(cy_name_list, ncov_data[date_str])], "world", is_map_symbol_show=False, name_map=countries_dict).set_series_opts( label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="19-nCoV\n%s" % date_str), legend_opts=opts.LegendOpts(is_show=False), visualmap_opts=opts.VisualMapOpts(max_=3000))) tl.add(map_, "%s" % date_str) tl.render("nCoV全球疫情地图({}).html".format(datetime.date.today()))
def gcv_main(): """ TODO """ # 生成时间轴的图 timeline = Timeline( init_opts=opts.InitOpts(width="1600px", height="800px")) commit_log = repo_analyze() contribute = {} for item in commit_log.itertuples(): top_commiter = get_topX(contribute, item, 5) timeline.add(get_commits_chart(time=item[1], \ names=top_commiter['author'].tolist(), \ c_insert=top_commiter['v1'].tolist(), \ c_delete=top_commiter['v2'].tolist(), \ c_add=top_commiter['v0'].tolist()), \ time_point=item[1]) # 1.0.0 版本的 add_schema 暂时没有补上 return self 所以只能这么写着 timeline.add_schema(is_auto_play=True, play_interval=100) timeline.render("git.html")
def print_bar(): x = ["no PV", "PV"] timeline1 = Timeline(init_opts=opts.InitOpts(bg_color="black")) for i in range(len(Grid)): price_noPV[i] = ('%.2f' % price_noPV[i]) price_opti[i] = ('%.2f' % price_opti[i]) bar = (Bar(init_opts=opts.InitOpts( bg_color="black")).add_xaxis(x).add_yaxis( "overall income", [price_noPV[i], price_opti[i]], color="rgb(30,144,255)", label_opts=opts.LabelOpts()).reversal_axis().set_series_opts( label_opts=opts.LabelOpts(position="right")). set_global_opts( title_opts=opts.TitleOpts( title="The overall income(USD) till time {}".format( time[i]), title_textstyle_opts=opts.TextStyleOpts(color="white")), yaxis_opts=opts.AxisOpts(axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(color="white"), ), axislabel_opts=opts.LabelOpts()), xaxis_opts=opts.AxisOpts(axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(color="white")), axislabel_opts=opts.LabelOpts()), legend_opts=opts.LegendOpts( textstyle_opts=opts.TextStyleOpts(color="white"), pos_left="right", pos_top="0%"), )) timeline1.add(bar, "{}年".format(i)).add_schema(play_interval=2000, is_auto_play=True, is_timeline_show=False) timeline1.render("C:/Users/suqi/Desktop/allcode/barnew.html")
def weather_show(path): # 定义时间线标题 title = ["最高气温", "昼夜温差", "降水量"] # 定义查询字段 field = ["high_temp", "differ_temp", "precipitation"] # 定义标记单位 remarks = ["温度(℃)", "温度(℃)", "降水量(mm)"] # 定义时间线对象 tl = Timeline() for i in range(3): # 查询数据 name, value = WeatherTrans().get_data(field[i], field[i]) # 统计表标题 bar_title = "2020年3月15日全国" + title[i] + "Top 10 城市" # 定义柱状图对象 bar = Bar() # 添加横坐标 bar.add_xaxis(name) # 添加纵坐标 bar.add_yaxis(remarks[i], value, label_opts=opts.LabelOpts(position="right")) # 绘制横向统计图 bar.reversal_axis() # 添加标题 bar.set_global_opts(title_opts=opts.TitleOpts(bar_title)) # 将统计图添加到时间线中 tl.add(bar, title[i]) # 生成html文件 tl.render(path)
def temp_show(field, name, path): # 定义时间滚动栏标题 title = TQHBTrans().get_date() print(title) # 创建时间线对象 tl = Timeline() for i in range(len(title)): print(i) data = TQHBTrans().get_temp(title[i], field) # 定义地图标题 map_title = str(title[i])[0:4] + "年" + str(title[i])[4:6] + "月" + str( title[i])[6:8] + "日全国各省会" + name + "分布图" # 创建地图对象 map0 = Map() # 向地图中添加数据 map0.add("", data, "china") # 创建地图显示方式 map0.set_global_opts(title_opts=opts.TitleOpts(title=map_title, ), visualmap_opts=opts.VisualMapOpts( is_piecewise=True, pieces=[{ "max": 40, "min": 31, "label": "31-40℃", "color": "#FF8000" }, { "max": 30, "min": 21, "label": "21-30℃", "color": "#FFBB77" }, { "max": 20, "min": 11, "label": "11-20℃", "color": "#FFDCB9" }, { "max": 10, "min": 1, "label": "1-10℃", "color": "#FFEEDD" }, { "max": 0, "min": -10, "label": "-10-0℃", "color": "#C4E1FF" }, { "max": -11, "min": -20, "label": "-20--11℃", "color": "#66B3FF" }, { "max": -21, "min": -30, "label": "-30--21℃", "color": "#2894FF" }])) # 将地图添加到时间线中 tl.add(map0, title[i]) # 生成html文件 tl.render(path)
def show_score_top(): # 查找上映年份集合 showtime = select_showtime() # 生成时间轴的图 timeline = Timeline( init_opts=opts.InitOpts(page_title="豆瓣电影TOP250-评分TOP10的电影", )) for year in showtime: film_tuple = select_film(year) date_list = select_data(year) timeline.add_schema(is_auto_play=True, play_interval=1000) # 柱状图初始化 bar = Bar() # 横坐标 bar.add_xaxis(film_tuple[0]) # 纵坐标 bar.add_yaxis( "", date_list, # 数据靠右显示 label_opts=opts.LabelOpts(is_show=True, position='right')) # 横纵坐标翻转 bar.reversal_axis() # 全局配置 bar.set_global_opts( # 标题 title_opts=opts.TitleOpts( title="豆瓣电影TOP250-第{}年评分TOP10的电影".format(year), pos_left='center'), # 横坐标隐藏 xaxis_opts=opts.AxisOpts(is_show=False, max_=select_film(year)[2], min_=(float(select_film(year)[3]) - 0.1), split_number=10), # 纵坐标 yaxis_opts=opts.AxisOpts( max_=9, # 字体大小 axislabel_opts=opts.LabelOpts(font_size=10), # 隐藏坐标轴 axisline_opts=opts.AxisLineOpts(is_show=False), # 隐藏刻度 axistick_opts=opts.AxisTickOpts(is_show=False))) # 组合组件 grid = (Grid().add(bar, grid_opts=opts.GridOpts(pos_top='8%', pos_bottom='12%', pos_left='25%'))) timeline.add(grid, "{}年".format(year)) timeline.add_schema(is_auto_play=True, play_interval=1000, is_loop_play=False, width='820px', pos_left='60px') # 生成HTML html = "pages/iframes/score_top.html" timeline.render("./templates/" + html) return html
def main(): df = pd.read_csv('../source_data.csv', usecols=['date', 'country', 'confirmed']) # 获取顺序的日期列表 date_list = list(set(df['date'].to_list())) date_list.sort() date_list = date_list[-20:] tl = Timeline() tl.add_schema(is_auto_play=False, play_interval=500, is_loop_play=False) draw_bar(df, date_list, tl) tl.render_notebook() tl.render("timeline_bar_with_graphic.html")
def get_visualization(datatype='Confirmed', increment_update=False, maptype='china-cities', save_png=False): v = Visualization(datatype=datatype, increment_update=increment_update, maptype=maptype) dates = v.dates dates = dates + dates[-1:] * 3 # 增量更新图片 if increment_update: for date in dates: if not os.path.exists( f"fig/png/COVID-19_{datatype}_{maptype}_{date}.png"): chart = v.get_day_chart(date=date) make_snapshot( snapshot, chart.render(), f"fig/png/COVID-19_{datatype}_{maptype}_{date}.png") else: timeline = Timeline(init_opts=opts.InitOpts( width="1440px", height="800px", theme=ThemeType.DARK)) for date in dates: if date <= '2020-01-23': continue try: chart = v.get_day_chart(date=date) timeline.add(chart, time_point=date[6:]) if save_png: make_snapshot( snapshot, chart.render(), f"fig/png/COVID-19_{datatype}_{maptype}_{date}.png") except Exception as e: print('get char error', date, e) timeline.add_schema( orient="vertical", is_auto_play=True, is_inverse=True, play_interval=1000, #播放间隔1000ms pos_left="null", pos_right="5", pos_top="20", pos_bottom="20", width="60", label_opts=opts.LabelOpts(is_show=True, color="#fff"), ) timeline.render(f"fig/html/COVID-19_{maptype}_{datatype}.html")
def print_bar(confirm_frame, timelist, all_province_name): tl = Timeline(init_opts=opts.InitOpts( page_title='疫情可视化', width='1080px', height='480px')) # 调节播放速率 ,是否自动播放,是否循环播放,是否显示时间轴 tl.add_schema(play_interval=300, is_auto_play=True, is_loop_play=False, is_timeline_show=True) l = len(timelist) for i in range(0, l): # 将每天的数据单独拿出来进行排序 s = {'province': all_province_name, 'confirm': confirm_frame.loc[:][i]} s = pd.DataFrame(s) # 翻转是镜像翻转所以 这里要从大到小排序 s = s.sort_values(by='confirm', ascending=1) province_name = s[-10:]['province'] confirm = s[-10:]['confirm'] heal_list, dead_list = get_Top10info(province_name, l - i) bar = Bar() bar.add_xaxis(province_name.to_list()) # 名字,数据,柱状图间距, label标签显示在右侧|这样翻转的时候就在右侧 # gap 神奇的参数因为每个柱状图有固定位置|宽度l, 正代表向正向移动百分比l,负代表向负向移动百分比l bar.add_yaxis('确诊人数', confirm.to_list(), label_opts=opts.LabelOpts(position='right'), color='#696969') bar.add_yaxis('治愈人数', heal_list, label_opts=opts.LabelOpts(position='right'), color='#90EE90') bar.add_yaxis('死亡人数', dead_list, label_opts=opts.LabelOpts(position='right'), color='#F08080') # 设置全局变量:x轴标签倾斜度,html主标题 bar.set_global_opts(legend_opts=opts.LegendOpts(is_show=True), xaxis_opts=opts.AxisOpts(name_rotate=-15), title_opts=opts.TitleOpts('当前日期:%s' % timelist[i], subtitle='数据来自inews')) bar.reversal_axis() tl.add(bar, timelist[i]) name = '疫情柱状图.html' print(name, '已成功生成到', os.getcwd()) tl.render(name)
def percent(self): """ 近六年四大富豪财富占比 :return: """ attr = ["马云家族", "马化腾", '王健林家族', '许家印'] tl = Timeline() for i in range(2015, 2020): pie = (Pie().add( "胡润排行榜", [(name, self.percent_search(name, i)[0].to_dict().get( EnumType.WEALTH)) for name in attr], rosetype="radius", radius=["30%", "55%"], ).set_global_opts( title_opts=opts.TitleOpts("{}年四大富豪财富占比".format(i)))) tl.add(pie, "{}年".format(i)) tl.render("timeline_pie.html")
def hotmap(year): timeline_1 = Timeline() for i in range(0, 4): if i == 0: a = 'confirmed' elif i == 1: a = 'suspected' elif i == 2: a = 'dead' elif i == 3: a = 'healed' list_i = listfilter2(i) map_1 = ( Map().set_global_opts( title_opts=opts.TitleOpts(title="2020年全国各省疫情"), visualmap_opts=opts.VisualMapOpts() # 最大数据范围 ).add(a, list_i, maptype="china")) timeline_1.add(map_1, "{}".format(a)) timeline_1.render("province_confirmed.html")
def plot_healDeadPie(): data = pd.read_csv('data\chinaDayData.csv') df = pd.DataFrame(data) #数据 date=df.iloc[:, 1].tolist() tl = Timeline() for i in range(len(data)): pie1 = ( Pie() .add( "商家A", [list(z) for z in zip(["死亡","治愈"],df.iloc[i,3:].tolist())], radius=["30%", "55%"], ) .set_global_opts(title_opts=opts.TitleOpts("中国{}日死亡率和治愈率比重".format(date[i]))) ) tl.add(pie1, "{}".format(date[i])) tl.render("visual_html\中国每日死亡人数与治愈人数比重饼图.html") return pie1
def timeline_map1() -> Timeline: a = Timeline() for i in range(2010, 2020): m = ( Map() .add("农业女性就业率",zip(list(农业女性就业.index),list(农业女性就业["{}".format(i)])), "world", is_map_symbol_show=False) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="{}年农业女性就业情况".format(i), subtitle=""), visualmap_opts=opts.VisualMapOpts(max_=100, is_piecewise=True), ) ) a.add(m, "{}".format(i)) a.render("./templates/ditu.html") with open("./templates/ditu.html", encoding="utf8", mode="r") as f: sym = "".join(f.readlines()) return render_template('2.html', the_sym=sym, )
def render(input_d): data, time_list, total_num, maxNum, output_name, title1, title2 = input_d minNum = 1 timeline = Timeline(init_opts=opts.InitOpts( width="1520px", height="720px", theme=ThemeType.DARK)) for y in time_list: g = get_year_chart(y, title1, title2) timeline.add(g, time_point=str(y)) timeline.add_schema( orient="vertical", is_auto_play=True, is_inverse=True, play_interval=5000, pos_left="null", pos_right="5", pos_top="20", pos_bottom="20", width="73", label_opts=opts.LabelOpts(is_show=True, color="#fff"), ) timeline.render(output_name)
def timeline(self): time_list = [str(d) for d in self.day] timeline = Timeline(init_opts=opts.InitOpts( width="1600px", height="900px", theme=self.theme)) for y in time_list: g = self.__get_year_chart(self.data, y) timeline.add(g, time_point=str(y[5:])) timeline.add_schema( orient="vertical", is_auto_play=True, is_inverse=True, play_interval=1000, pos_left="null", pos_right="5", pos_top="20", pos_bottom="20", width="60", ) save = self.save + ".html" print(save) timeline.render(save)
def timeline_map2() -> Timeline: df = pd.read_csv('fenshenggdp.csv') tl = Timeline() for i in range(2017, 2014): map0 = (Map().add( "各省GDP(亿元)", zip(list(df.地区), list(df["{}".format(i)])), "china", is_map_symbol_show=False).set_series_opts( label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts(title="{}全国各省GDP".format(i), subtitle=""), visualmap_opts=opts.VisualMapOpts(min_=900, max_=90000, is_piecewise=True), )) tl.add(map0, "{}".format(i)) tl.render("./templates/2.html") with open("./templates/2.html", encoding="utf8", mode="r") as f: plot_all = "".join(f.readlines()) return render_template( 'the_fenshenggdp.html', the_fenshenggdp=plot_all, )
def timeline_map1() -> Timeline: df = pd.read_csv('nengyuanxiaohao.csv') tl = Timeline() for i in range(2017, 2014): map0 = (Map().add( "碳煤石油天然气消耗量(万吨标准煤)", zip(list(df.地区), list(df["{}".format(i)])), "china", is_map_symbol_show=False).set_series_opts( label_opts=opts.LabelOpts(is_show=False)).set_global_opts( title_opts=opts.TitleOpts( title="{}国各省碳煤石油天然气消耗量".format(i), subtitle=""), visualmap_opts=opts.VisualMapOpts(min_=30, max_=6000, is_piecewise=True), )) tl.add(map0, "{}".format(i)) tl.render("./templates/3.html") with open("./templates/3.html", encoding="utf8", mode="r") as f: plot_all = "".join(f.readlines()) return render_template( '5.html', the_map=plot_all, )
def industry_percent(self): """ 近六年排行榜前20行业财富占比 :return: """ tl = Timeline() res = defaultdict(int) for i in [2015, 2020]: for result in self.industry_search(i): result = result.to_dict() name = result.get(EnumType.NAME_CN) res[self.industry[self.industry_map.get(name)]] += int( result.get(EnumType.WEALTH)) pie = (Pie().add( "胡润排行榜", list(zip(res.keys(), res.values())), rosetype="radius", radius=["30%", "55%"], center="center").set_global_opts( title_opts=opts.TitleOpts("{}年行业财富".format(i)))) tl.add(pie, "{}年".format(i)) tl.render("industry_pie.html")
def timeline_map(width='800px', height='500px') -> Timeline: year = df.columns.values.tolist()[7:] tl = Timeline(opts.InitOpts(width=width, height=height, theme=ThemeType.INFOGRAPHIC)) for i in year: map0 = ( Map() .add( "生育率", list(zip(list(df.country), list(df["{}".format(i)]))), "world", is_map_symbol_show=False ) .set_series_opts(label_opts=opts.LabelOpts(is_show=False)) .set_global_opts( title_opts=opts.TitleOpts(title="{}年世界生育率".format(i), subtitle="", subtitle_textstyle_opts=opts.TextStyleOpts(color="red", font_size=18, font_style="italic")), # 设置副标题样式,进行图例说明 visualmap_opts=opts.VisualMapOpts(max_=8), ) ) tl.add(map0, "{}年".format(i)) return tl.render('app/templates/pyecharts/jiaohu/jiaohu_t1.html')
tooltip_opts=opts.TooltipOpts(is_show=True, trigger="axis", axis_pointer_type="shadow"), xaxis_opts=opts.AxisOpts(name='单位: 英寸'), yaxis_opts=opts.AxisOpts(name='销量: 台')).set_series_opts( label_opts=opts.LabelOpts(is_show=True), markline_opts=opts.MarkLineOpts(data=[ opts.MarkLineItem(type_="average", name="平均值"), ]), )) pie = (Pie().add( series_name="销售占比", data_pair=[["小屏(<=38寸)", classified_data[month][0]], ["中等大小屏幕", classified_data[month][1]], ["大屏(>=65寸)", classified_data[month][2]]], center=["25%", "35%"], radius="28%", ).set_series_opts( tooltip_opts=opts.TooltipOpts(is_show=True, trigger="item"))) return bar.overlap(pie) # 生成时间轴的图 timeline = Timeline(init_opts=opts.InitOpts(width="1400px", height="700px")) for m in range(3, 11): timeline.add(get_month_overlap_chart(month=m), time_point=str(m)) timeline.add_schema(is_auto_play=True, play_interval=1000) timeline.render("sellStats.html")
{ 'min': 1000, 'max': 5000, 'label': '1000-5000', 'color': '#e57373' }, { 'min': 1000, 'label': '5000+', 'color': '#c62828' }, ] # noinspection PyTypeChecker map.add('', zip(provices, valuse)) map.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) map.set_global_opts( visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=pieces, pos_left='100px'), tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{b}<br/>{c}"), ) filepath = 'Maps/' + time + '.html' map.render(path=filepath) tl.add(map, "{}".format(time)) tl.render("ChinaChart/ChinaMap.html")
from pyecharts import options as opts from pyecharts.charts import Bar, Timeline from pyecharts.faker import Faker tl = Timeline() for i in range(2015, 2020): bar = (Bar().add_xaxis(Faker.choose()).add_yaxis( "商家A", Faker.values(), label_opts=opts.LabelOpts(position="right")).add_yaxis( "商家B", Faker.values(), label_opts=opts.LabelOpts( position="right")).reversal_axis().set_global_opts( title_opts=opts.TitleOpts( "Timeline-Bar-Reversal (时间: {} 年)".format(i)))) tl.add(bar, "{}年".format(i)) tl.render("timeline_bar_reversal.html")
init_opts=opts.InitOpts( width='1220px', height='900px', )) for it in headers: tmp = pd_exp_fz_2[['INDIC_KEY', it]] pie = ( Pie().add( "资产负债表", [list(z) for z in zip(tmp['INDIC_KEY'], tmp[it])], # 是否展示成南丁格尔图,通过半径区分数据大小,有'radius'和'area'两种模式。 # radius:扇区圆心角展现数据的百分比,半径展现数据的大小 # area:所有扇区圆心角相同,仅通过半径展现数据大小 rosetype="radius", # 饼图的半径,数组的第一项是内半径,第二项是外半径 # 默认设置成百分比,相对于容器高宽中较小的一项的一半 radius=["30%", "60%"], label_opts=opts.LabelOpts(position="center") # 提示框组件配置项,参考 `series_options.TooltipOpts` # tooltip_opts= Union[opts.TooltipOpts, dict, None] = None, ).set_global_opts( title_opts=opts.TitleOpts("蒙商银行资产结构情况:"), legend_opts=opts.LegendOpts( orient="vertical", pos_top="15%", pos_left="2%")).set_series_opts(label_opts=opts.LabelOpts( formatter="{b}: {d}%"))) tl.add(pie, "{}".format(it)) tl.render("timeline_pie.html")
for time in populations.index: values = populations.loc[time].tolist() popu_map = Map() popu_map.add("", [list(z) for z in zip(attr, values)], maptype="china", is_map_symbol_show=False) popu_map.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) popu_map.set_global_opts(title_opts=opts.TitleOpts( title="China population by province from 2000 to 2018", subtitle="Units: 10K"), visualmap_opts=opts.VisualMapOpts( max_=12000, is_piecewise=True, split_number=12, range_color=colors), toolbox_opts=opts.ToolboxOpts()) time_map.add(popu_map, "{}".format(time)) time_map.render("plots/population-map-over-time.html") #动态展示各省市人口变化 sorted_pops = [] for year in range(2000, 2019): populations.sort_values(year, axis=1, inplace=True) sorted_pops.append( [year, populations.loc[year].tolist(), populations.columns.tolist()]) import plot_population_by_province plot = plot_population_by_province.Plot(sorted_pops) plot.showGif('plots/population-by-province.gif')
#定义每日地图绘制函数 def map_visualmap(sequence, date): c = Map() c.add(date, sequence, maptype="world", label_opts=opts.LabelOpts(is_show=False, font_size=8), is_map_symbol_show=False, is_roam=True) c.set_global_opts(title_opts=opts.TitleOpts(title=titleIn,subtitle="数据来源约翰霍普金斯大学JHU CSSE"), legend_opts=opts.LegendOpts(is_show=False),visualmap_opts=opts.VisualMapOpts(is_piecewise=True,\ pieces=pieces_list)) return c for i in range(n): #取每日数据 row = df2.iloc[i, ].tolist() #将数据转换为二元的列表 sequence_temp = list(zip(attr, row)) #对日期格式化以便显示 time = format(df2.index[i], "%Y-%m-%d") #创建地图 map_temp = map_visualmap(sequence_temp, time) #将地图加入时间轴对象 timeLine.add(map_temp, time).add_schema(play_interval=360, is_auto_play=False, is_loop_play=False) # 地图创建完成后,通过render()方法可以将地图渲染为html timeLine.render(fileNameOut)
from pyecharts import options as opts from pyecharts.charts import Bar, Timeline from pyecharts.faker import Faker tl = Timeline() for i in range(2015, 2020): bar = (Bar().add_xaxis(Faker.choose()).add_yaxis( "商家A", Faker.values()).add_yaxis("商家B", Faker.values()).set_global_opts( title_opts=opts.TitleOpts("某商店{}年营业额".format(i)))) tl.add(bar, "{}年".format(i)) tl.render("Timeline_multi_axis.html")