def v_positions(self, date=yesterdayobj(), rendered=True): """ pie chart visualization of positions ratio in combination """ sdata = sorted( [ (fob.name, fob.briefdailyreport(date).get("currentvalue", 0)) for fob in self.fundtradeobj ], key=lambda x: x[1], reverse=True, ) pie = Pie() pie.add( series_name="总值占比", data_pair=sdata, label_opts=opts.LabelOpts(is_show=False, position="center"), ).set_global_opts( legend_opts=opts.LegendOpts( pos_left="left", type_="scroll", orient="vertical" ) ).set_series_opts( tooltip_opts=opts.TooltipOpts( trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)" ), ) if rendered: return pie.render_notebook() else: return pie
def v_positions(self, date=yesterdayobj(), vopts=None): """ pie chart visualization of positions ratio in combination """ sdata = sorted( [(fob.aim.name, fob.briefdailyreport(date).get("currentvalue", 0)) for fob in self.fundtradeobj], key=lambda x: x[1], reverse=True, ) pie = Pie() if vopts is None: vopts = pie_opts pie.add(series_name="总值占比", data_pair=sdata) pie.set_global_opts(**vopts) return pie.render_notebook()
def v_category_positions(self, date=yesterdayobj(), rendered=True): """ 资产分类扇形图,按大类资产求和绘制 :param date: :param rendered: bool. default true for notebook, for plain pyechart obj to return, set rendered=False :return: """ d = {} for f in self.fundtradeobj: if isinstance(f, itrade): t = f.get_type() if t == "场内基金": t = get_fund_type(f.code[2:]) elif f.code == "mf": t = "货币基金" else: t = get_fund_type(f.code) if t == "其他": logger.warning( "%s has category others which should be double checked" % f.code ) d[t] = d.get(t, 0) + f.briefdailyreport(date).get("currentvalue", 0) sdata = sorted([(k, round(v, 2)) for k, v in d.items()]) pie = Pie() pie.add( series_name="总值占比", data_pair=sdata, label_opts=opts.LabelOpts(is_show=False, position="center"), ).set_global_opts( legend_opts=opts.LegendOpts( pos_left="left", type_="scroll", orient="vertical" ) ).set_series_opts( tooltip_opts=opts.TooltipOpts( trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)" ), ) if rendered: return pie.render_notebook() else: return pie
pie1.set_global_opts(title_opts=opts.TitleOpts(title='Rose chart example'), legend_opts=opts.LegendOpts(is_show=False), toolbox_opts=opts.ToolboxOpts()) # Set series configuration items pie1.set_series_opts(label_opts=opts.LabelOpts( is_show=True, position="inside", font_size=12, formatter="{b}:{c}day", font_style="italic", font_weight="bold", font_family="Microsoft YaHei"), ) # Generate html document # pie1.render('nightingale rose. html ') # Use magic command to display rose chart in notebook pie1.render_notebook() # 饼图 import random from pyecharts import options as opts from pyecharts.charts import Page, Pie pie = ( Pie().add( '鼠标选中分区后的tip', [ list(z) for z in zip( [ '20{}年第{}季'.format(year, season) for year in [19, 20] # count 2 for season in range(1, 5) ] # count 2
a = df['name'].values.tolist() b = df['dead'].values.tolist() n = len(a) rosechart = Pie(init_opts=opts.InitOpts(width='1350px', height='750px')) color_series = np.random.random((n, 3)) # rosechart.set_colors(color_series) # Add data, set the radius of pie chart, and show it as Nightingale chart or not rosechart.add("", [list(z) for z in zip(a, b)], radius=["5%", "95%"], center=["30%", "60%"], rosetype="area") # Set global configuration item rosechart.set_global_opts(title_opts=opts.TitleOpts(title='新冠肺炎各国累计死亡数 ' + str(df['date'][0])), legend_opts=opts.LegendOpts(is_show=False), toolbox_opts=opts.ToolboxOpts()) # Set the serial configuration item to be labeled outside rosechart.set_series_opts( label_opts=opts.LabelOpts( is_show=True, position="outside", # inside, outside font_size=14, formatter="{b}:{c}", font_style="italic", font_weight="bold", font_family="Microsoft YaHei"), ) rosechart.render('a.html') rosechart.render_notebook()
# 高校数量前十名 pie = Pie() pie.add("", [ list(z) for z in zip(data['name'].values.tolist()[:10], data['counts'].values.tolist()[:10]) ], radius=["30%", "75%"], center=["40%", "50%"], rosetype="radius") pie.set_global_opts( title_opts=opts.TitleOpts(title="高校数量前十名"), legend_opts=opts.LegendOpts(type_="scroll", pos_left="80%", orient="vertical"), ) pie.render_notebook() # 高校数量后十名 pie = Pie() pie.add("", [ list(z) for z in zip(data['name'].values.tolist()[-10:], data['counts'].values.tolist()[-10:]) ], radius=["30%", "75%"], center=["40%", "50%"], rosetype="radius") pie.set_global_opts( title_opts=opts.TitleOpts(title="高校数量后十名"), legend_opts=opts.LegendOpts(type_="scroll", pos_left="80%", orient="vertical"),