def bar_graphic_component() -> Bar: c = (Bar().add_xaxis(Faker.choose()).add_yaxis( "商家A", Faker.values()).add_yaxis("商家B", Faker.values()).set_global_opts( title_opts=opts.TitleOpts(title="Bar-Graphic 组件示例"), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( rotation=JsCode("Math.PI / 4"), bounding="raw", right=110, bottom=110, z=100, ), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_shape_opts=opts.GraphicShapeOpts( width=400, height=50), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)"), ), opts.GraphicText( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_textstyle_opts=opts.GraphicTextStyleOpts( text="pyecharts bar chart", font="bold 26px Microsoft YaHei", graphic_basicstyle_opts=opts. GraphicBasicStyleOpts(fill="#fff"), ), ), ], ) ], )) return c
def syz_mark(): """私人标记""" graphic_opts = [ opts.GraphicGroup( graphic_item=opts.GraphicItem( rotation=JsCode("Math.PI / 4"), bounding="raw", right=80, bottom=80, z=100, ), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem( left="center", top="center", z=100 ), graphic_shape_opts=opts.GraphicShapeOpts( width=400, height=50 ), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)" ), ), opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="center", z=100 ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( text="云博", font="bold 26px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff" ), ), ), ], ) ] return graphic_opts
def test_timeline_graphic(self): self.tl.add_schema(graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( rotation=JsCode("Math.PI / 4"), bounding="raw", right=110, bottom=110, z=100, ), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem( left="center", top="center", z=100), graphic_shape_opts=opts.GraphicShapeOpts(width=400, height=50), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)"), ), opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="center", z=100), graphic_textstyle_opts=opts.GraphicTextStyleOpts( text="pyecharts bar chart", font="bold 26px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff"), ), ), ], ) ]) assert_equal( type(opts.GraphicGroup()), type( self.tl.options.get("baseOption").get("timeline").get( "graphic")[0]), )
def plot_timeline(df, data1 = 'Nuevos casos', data2 = 'Hospitalizados'): """[summary] Parameters ---------- df : [type] [description] data1 : str, optional [description], by default 'Nuevos casos' data2 : str, optional [description], by default 'Hospitalizados' """ tl = Timeline() calendar_dict = { 1:'Ene', 2:'Feb', 3:'Mar', 4:'Abr', 5:'May', 6:'Jun', 7:'Jul', 8:'Ag', 9:'Sep', 10:'Oct', 11:'Nov', 12:'Dic' } for i in range(3, df.Mes.max()+1): bar = ( Bar() .add_xaxis(pd.unique(df.Territorio).tolist()) .add_yaxis(data1, df[df.Mes == i][data1].tolist()) .add_yaxis(data2, df[df.Mes == i][data2].tolist()) .set_global_opts( title_opts=opts.TitleOpts("Covid19 mes a mes"), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( rotation=JsCode("Math.PI / 4"), bounding="raw", right=100, bottom=110, z=100, ), ) ], ) ) tl.add(bar,calendar_dict[i]) st_pyecharts(tl)
def bar_graphic_image_with_js_component() -> Grid: bar = ( Bar(init_opts=opts.InitOpts(chart_id="1234")) .add_xaxis(Faker.choose()) .add_yaxis("商家A", Faker.values()) .add_yaxis("商家B", Faker.values()) .set_global_opts( title_opts=opts.TitleOpts(title="Bar-Graphic Image(旋转功能)组件示例"), graphic_opts=[ opts.GraphicImage( graphic_item=opts.GraphicItem( id_="logo", right=20, top=20, z=-10, bounding="raw", origin=[75, 75], ), graphic_imagestyle_opts=opts.GraphicImageStyleOpts( image="http://echarts.baidu.com/images/favicon.png", width=150, height=150, opacity=0.4, ), ) ], ) ) c = ( Grid(init_opts=opts.InitOpts(chart_id="1234")) .add( chart=bar, grid_opts=opts.GridOpts(pos_left="5%", pos_right="4%", pos_bottom="5%"), ) .add_js_funcs( """ var rotation = 0; setInterval(function () { chart_1234.setOption({ graphic: { id: 'logo', rotation: (rotation += Math.PI / 360) % (Math.PI * 2) } }); }, 30); """ ) ) return c
def test_bar_graphic(fake_writer): c = (Bar().add_xaxis(["A", "B", "C"]).add_yaxis( "series0", [1, 2, 4]).set_global_opts(graphic_opts=[ opts.GraphicImage( graphic_item=opts.GraphicItem( id_="logo", right=20, top=20, z=-10, bounding="raw", origin=[75, 75], ), graphic_imagestyle_opts=opts.GraphicImageStyleOpts( image="http://echarts.baidu.com/images/favicon.png", width=150, height=150, opacity=0.4, ), ) ])) c.render() file_name, content = fake_writer.call_args[0] eq_("render.html", file_name) assert_in("graphic", content)
offset: 1, color: 'rgba(0, 77, 167, 1)' } ], false) """ ), "barBorderRadius": [30, 30, 30, 30], "shadowColor": "rgb(0, 160, 221)" } } } GRAPH = { "text": lambda x: opts.GraphicText( graphic_item = opts.GraphicItem( left="center", top="center", z=100 ), graphic_textstyle_opts = ( text=x, font="bold 26px Microsoft Yahei", graphic_basicstyle_opts=opts.GraphicBacisStyleOpts( fill="#ffffff" ) ) ), "rect": opts.GraphicRect( graphic_item = opts.GraphicItem( left="center", top="center", z=100
def grid_horizontal() -> Grid: bar0 = ( Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) .add_xaxis(['高收入国家', '低收入国家', '中低等收入国家', '中高等收入国家']) .add_yaxis("Income_Group", [high, low, middle_low, middle_high]) .set_global_opts(title_opts=opts.TitleOpts(title="Income_Group", subtitle="2019", pos_left="2%"), legend_opts=opts.LegendOpts(pos_left="20%")) ) bar = ( Bar() .set_global_opts( title_opts=opts.TitleOpts(title=""), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( # 控制整体的位置 left="52%", top="7%", ), children=[ # opts.GraphicRect控制方框的显示 # 如果不需要方框,去掉该段即可 opts.GraphicRect( graphic_item=opts.GraphicItem( z=100, left="center", top="middle", ), graphic_shape_opts=opts.GraphicShapeOpts( width=415, height=440, ), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff", stroke="#555", line_width=2, shadow_blur=8, shadow_offset_x=3, shadow_offset_y=3, shadow_color="rgba(0,0,0,0.3)", ) ), # opts.GraphicText控制文字的显示 opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="middle", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=JsCode( "['世界银行是按人均国民总收入对世界各国经济发展水平进行分组。 '," "'通常把世界各国分成四组,'," "'即低收入国家、中等偏下收入国家、'," "'中等偏上收入国家和高收入国家。'," "'但以上标准不是固定不变的,而是随着经济的发展不断进行调整。'," "'中等偏下收入国家和中等偏上收入国家合称为中等收入国家。'," "' '," "'按世界银行(World Bank)公布的数据,'," "'2018年的最新收入分组标准为:'," "'人均国民总收入低于995美元为低收入国家,'," "'在996至3895美元之间为中等偏下收入国家,'," "'在3896至12055元之间为中等偏上收入国家,'," "'高于12055美元为高收入国家。'," "' '," "'此图所统计的217个经济体中,'," "'高收入国家79个,低收入国家31个,'," "'中低等收入国家47个,中高等收入国家60个。'," "'由此看出,'," "'全球大多数国家收入水平都处于中等收入水平或者高收入水平,'," "'只有少部分国家处于低收入水平。'," "' '," "'美国、日本、英法德以及韩国等为高收入国家;'," "'俄罗斯、巴西、中国、土耳其、马来西亚等'," "'目前是中高等收入国家;'," "'印度、巴基斯坦、越南、菲律宾等国为中低收入国家;'," "'阿富汗、坦桑尼亚、柬埔寨、尼泊尔、埃塞俄比亚等'," "'为低收入国家。'].join('\\n')" ), font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333" ) ) ) ] ) ], ) ) grid = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_left="55%")) .add(bar0, grid_opts=opts.GridOpts(pos_right="55%")) ) return grid
from pyecharts import options as opts from pyecharts.charts import Bar from pyecharts.commons.utils import JsCode from pyecharts.faker import Faker c = (Bar().add_xaxis(Faker.choose()).add_yaxis( "商家A", Faker.values()).add_yaxis("商家B", Faker.values()).set_global_opts( title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 2 组件示例"), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem(left="50%", top="15%"), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem(z=100, left="center", top="middle"), graphic_shape_opts=opts.GraphicShapeOpts(width=190, height=90), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff", stroke="#555", line_width=2, shadow_blur=8, shadow_offset_x=3, shadow_offset_y=3, shadow_color="rgba(0,0,0,0.3)", ), ), opts.GraphicText( graphic_item=opts.GraphicItem(left="center", top="middle",
def find_correlation_render(attributes, data, pearsonr, query, table_path, answer): dimensions = len(attributes) if dimensions == 2: data[0] = list(map(str, data[0])) data[1] = list(map(float, data[0])) l1_1 = Scatter() l1_1.add_xaxis(data[0]) l1_1.add_yaxis("", data[1]) l1_1.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts(name=attributes[0]), yaxis_opts=opts.AxisOpts(name=attributes[1]), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) grid = Grid(init_opts=opts.InitOpts( width="100%", height="100%", renderer=globals.RenderType.SVG, )) grid.add(l1_1, grid_opts={'left': '15%', 'bottom': '34%'}) option1 = grid.dump_options_with_quotes() option1 = json.loads(option1) option = {"option": [option1], "query": query} return option elif dimensions == 3: l1_1 = Scatter() data[0] = list(map(str, data[0])) data[1] = list(map(float, data[1])) data[2] = list(map(float, data[2])) l1_1.add_xaxis(data[0]) l1_1.add_yaxis("", data[1]) l1_1.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts( name=attributes[0], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=0, ), yaxis_opts=opts.AxisOpts( name=attributes[1], grid_index=0, ), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) l1_2 = Scatter() l1_2.add_xaxis(data[0]) l1_2.add_yaxis("", data[2]) l1_2.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts( name=attributes[0], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=1, ), yaxis_opts=opts.AxisOpts(name=attributes[2], grid_index=1), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) data[1] = list(map(str, data[1])) l2_1 = Scatter() l2_1.add_xaxis(data[1]) l2_1.add_yaxis("", data[2]) l2_1.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts(name=attributes[0], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=2), yaxis_opts=opts.AxisOpts(name=attributes[1], grid_index=2), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) grid = Grid(init_opts=opts.InitOpts( width="100%", height="100%", renderer=globals.RenderType.SVG, )) grid.add( chart=l1_1, grid_opts=opts.GridOpts(pos_right="57%", pos_bottom="20%", pos_top="40%"), grid_index=0, ) grid.add( chart=l1_2, grid_opts=opts.GridOpts(pos_left="57%", pos_bottom="20%", pos_top="40%"), grid_index=1, ) grid.add( chart=l2_1, grid_opts=opts.GridOpts(pos_right="57%", pos_bottom="60%"), grid_index=2, ) option1 = grid.dump_options_with_quotes() option1 = json.loads(option1) option = {"option": [option1], "query": query} return option elif dimensions == 4: data[0] = list(map(str, data[0])) data[1] = list(map(float, data[1])) data[2] = list(map(float, data[2])) data[3] = list(map(float, data[3])) l1_1 = Scatter() l1_1.add_xaxis(data[0]) l1_1.add_yaxis("", data[1]) l1_1.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts( name=attributes[0], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=0, ), yaxis_opts=opts.AxisOpts( name=attributes[1], grid_index=0, ), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) l1_2 = Scatter() l1_2.add_xaxis(data[0]) l1_2.add_yaxis("", data[2]) l1_2.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts( name=attributes[0], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=1, ), yaxis_opts=opts.AxisOpts(name=attributes[2], grid_index=1), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) l2_1 = Scatter() l2_1.add_xaxis(data[0]) l2_1.add_yaxis("", data[3]) l2_1.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts(name=attributes[0], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=2), yaxis_opts=opts.AxisOpts(name=attributes[3], grid_index=2), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) data[1] = list(map(str, data[1])) l2_2 = Scatter() l2_2.add_xaxis(data[1]) l2_2.add_yaxis("", data[2]) l2_2.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts(name=attributes[1], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=3), yaxis_opts=opts.AxisOpts(name=attributes[2], grid_index=3), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) grid = Grid(init_opts=opts.InitOpts( width="100%", height="100%", renderer=globals.RenderType.SVG, )) grid.add( chart=l1_1, grid_opts=opts.GridOpts(pos_right="57%", pos_bottom="20%", pos_top="40%"), grid_index=0, ) grid.add( chart=l1_2, grid_opts=opts.GridOpts(pos_left="57%", pos_bottom="20%", pos_top="40%"), grid_index=1, ) grid.add( chart=l2_1, grid_opts=opts.GridOpts(pos_right="57%", pos_bottom="60%"), grid_index=2, ) grid.add( chart=l2_2, grid_opts=opts.GridOpts(pos_left="57%", pos_bottom="60%"), grid_index=3, ) r1_1 = Scatter() r1_1.add_xaxis(data[1]) r1_1.add_yaxis("", data[3]) r1_1.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts(name=attributes[1], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=0), yaxis_opts=opts.AxisOpts(name=attributes[3], grid_index=0), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) data[2] = list(map(str, data[2])) r1_2 = Scatter() r1_2.add_xaxis(data[2]) r1_2.add_yaxis("", data[3]) r1_2.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts(name=attributes[2], axislabel_opts=opts.LabelOpts(rotate=50, interval=0), grid_index=1), yaxis_opts=opts.AxisOpts(name=attributes[3], grid_index=1), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) grid1 = Grid(init_opts=opts.InitOpts( width="100%", height="100%", renderer=globals.RenderType.SVG, )) grid1.add( chart=r1_1, grid_opts=opts.GridOpts(pos_right="57%", pos_bottom="30%"), grid_index=0, ) grid1.add( chart=r1_2, grid_opts=opts.GridOpts(pos_left="57%", pos_bottom="30%"), grid_index=1, ) option1 = grid.dump_options_with_quotes() option1 = json.loads(option1) option2 = grid1.dump_options_with_quotes() option2 = json.loads(option2) option = {"option": [option1, option2], "query": query} return option
def get_year_chart(data, all_data, year): map_data = [[[x["name"], x["value"]] for x in d["data"]] for d in data if d["time"] == year][0] map_temp_data = [[[x["name"], x["value"][0]] for x in d["data"]] for d in all_data if d["time"] == year][0] min_data, max_data = ( min([d[1][0] for d in map_data]), max([d[1][0] for d in map_data]), ) #map = Map(init_opts=opts.InitOpts(width="1900px", height="900px", bg_color="#ADD8E6",page_title="4.15全球疫情确诊人数", theme="white")) map_chart = ( Map().add( maptype="world", #默认地图为中国地图,加上这个参数改成世界地图 series_name="", data_pair=map_temp_data, label_opts=opts.LabelOpts(is_show=False), is_map_symbol_show=False, itemstyle_opts={ "normal": { "areaColor": "#323c48", "borderColor": "#404a59" }, "emphasis": { "label": { "show": Timeline }, "areaColor": "rgba(255,255,255, 0.5)", }, }, ).set_global_opts( title_opts=opts.TitleOpts( title="世界各国现存确诊人数变化", subtitle="确诊人数单位:例", pos_left="center", pos_top="top", title_textstyle_opts=opts.TextStyleOpts( font_size=25, color="rgba(255,255,255, 0.9)"), ), tooltip_opts=opts.TooltipOpts( is_show=True, formatter=JsCode("""function(params) { if ('value' in params.data) { return params.data.value[2] + ': ' + params.data.value[0]; } }"""), ), visualmap_opts=opts.VisualMapOpts( is_calculable=True, dimension=0, pos_left="10", pos_top="center", range_text=["High", "Low"], range_color=["lightskyblue", "yellow", "orangered"], textstyle_opts=opts.TextStyleOpts(color="#ddd"), min_=min_data, max_=max_data, ), )) bar_x_data = [x[0] for x in map_data] # 这里注释的部分会导致 label 和 value 与 饼图不一致 # 使用下面的 List[Dict] 就可以解决这个问题了。 # bar_y_data = [x[1][0] for x in map_data] bar_y_data = [{"name": x[0], "value": x[1][0]} for x in map_data] bar = (Bar().add_xaxis(xaxis_data=bar_x_data).add_yaxis( series_name="", yaxis_index=1, y_axis=bar_y_data, label_opts=opts.LabelOpts(is_show=True, position="right", formatter="{b}: {c}"), ).reversal_axis().set_global_opts( xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)), yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)), tooltip_opts=opts.TooltipOpts(is_show=False), visualmap_opts=opts.VisualMapOpts( is_calculable=True, dimension=0, pos_left="10", pos_top="center", range_text=["High", "Low"], range_color=["lightskyblue", "yellow", "orangered"], textstyle_opts=opts.TextStyleOpts(color="#ddd"), min_=min_data, max_=max_data, ), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( rotation=JsCode("Math.PI / 4"), bounding="raw", right=110, bottom=110, z=100, ), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_shape_opts=opts.GraphicShapeOpts(width=400, height=50), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)"), ), opts.GraphicText( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_textstyle_opts=opts.GraphicTextStyleOpts( text=f"{str(year)}", font="bold 26px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff"), ), ), ], ) ], )) pie_data = [[x[0], x[1][0]] for x in map_data] percent_sum = sum([x[1][1] for x in map_data]) rest_value = 0 for d in map_data: rest_percent = 100.0 rest_percent = rest_percent - percent_sum if d[1][1] != 0: rest_value = d[1][0] * (rest_percent / d[1][1]) break pie_data.append(["其他国家", rest_value]) pie = (Pie().add( series_name="", data_pair=pie_data, radius=["12%", "20%"], center=["75%", "85%"], itemstyle_opts=opts.ItemStyleOpts(border_width=1, border_color="rgba(0,0,0,0.3)"), ).set_global_opts( tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"), legend_opts=opts.LegendOpts(is_show=False), )) grid_chart = (Grid().add( bar, grid_opts=opts.GridOpts(pos_left="10", pos_right="45%", pos_top="70%", pos_bottom="5"), ).add(pie, grid_opts=opts.GridOpts()).add(map_chart, grid_opts=opts.GridOpts())) return grid_chart
def get_year_chart(date): data = pd.read_csv('./china/{}.csv'.format(date)) df_clear = data.drop(data[(data['地区'] == '香港')].index) df_clear1 = df_clear.drop(df_clear[df_clear['新增确诊'] == 0].index) df_clear2 = df_clear.drop(df_clear[df_clear['现有确诊'] == 0].index) name = list(df_clear['地区']) nowConfirm = list(df_clear1['新增确诊']) confirm = list(df_clear2['现有确诊']) heal = list(df_clear['治愈']) dead = list(df_clear['死亡']) map_chart = (Map().add( series_name="", data_pair=[list(z) for z in zip(name, confirm)], label_opts=opts.LabelOpts(is_show=False), is_map_symbol_show=False, ).set_global_opts( title_opts=opts.TitleOpts( title="现有疫情和新增疫情", subtitle="中国", pos_left="center", pos_top="top", title_textstyle_opts=opts.TextStyleOpts( font_size=25, color="rgba(255,255,255, 0.9)"), ), tooltip_opts=opts.TooltipOpts(is_show=True, ), visualmap_opts=opts.VisualMapOpts( is_calculable=True, dimension=0, pos_left="10", pos_top="center", range_text=["高风险地区", "低风险地区"], range_color=["lightskyblue", "yellow", "orangered"], textstyle_opts=opts.TextStyleOpts(color="#ddd"), min_=0, max_=100, ), )) bar = (Bar().add_xaxis(xaxis_data=name).add_yaxis( series_name="", yaxis_index=1, y_axis=confirm, label_opts=opts.LabelOpts(is_show=True, position="right", formatter="{b}: {c}"), ).reversal_axis().set_global_opts( xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)), yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)), tooltip_opts=opts.TooltipOpts(is_show=False), visualmap_opts=opts.VisualMapOpts( is_calculable=True, dimension=0, pos_left="10", pos_top="center", range_text=["高风险地区", "低风险地区"], range_color=["lightskyblue", "yellow", "orangered"], textstyle_opts=opts.TextStyleOpts(color="#ddd"), min_=0, max_=100, ), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( bounding="raw", right=110, bottom=11, z=100, ), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_shape_opts=opts.GraphicShapeOpts(width=400, height=50), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)"), ), opts.GraphicText( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_textstyle_opts=opts.GraphicTextStyleOpts( text=date, font="bold 26px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff"), ), ), ], ) ], )) pie = (Pie().add( series_name="", data_pair=[list(z) for z in zip(name, nowConfirm)], radius=["12%", "20%"], center=["75%", "85%"], itemstyle_opts=opts.ItemStyleOpts(border_width=1, border_color="rgba(0,0,0,0.3)"), ).set_global_opts( tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"), legend_opts=opts.LegendOpts(is_show=False), )) grid_chart = (Grid().add( bar, grid_opts=opts.GridOpts(pos_left="10", pos_right="45%", pos_top="70%", pos_bottom="5"), ).add(pie, grid_opts=opts.GridOpts()).add(map_chart, grid_opts=opts.GridOpts())) return grid_chart
def find_extremum_render(x,y,x_name,y_name,query,operator,answer): x=list(map(str,x)) y=list(map(float,y)) makepoint=[] makeline=[] if operator=="MAX": makepoint.append(opts.MarkPointItem(type_="max",value="max",itemstyle_opts=opts.ItemStyleOpts(opacity=0.6))) makeline.append(opts.MarkPointItem(type_="max", value="max")) else: makepoint.append(opts.MarkPointItem(type_="min", value="min", itemstyle_opts=opts.ItemStyleOpts(opacity=0.6))) makeline.append(opts.MarkPointItem(type_="min", value="min")) line=Line() line.add_xaxis(x) line.add_yaxis( y_name, y_axis=y, label_opts=opts.LabelOpts(is_show=False), symbol_size='100%', markpoint_opts=opts.MarkPointOpts( data=makepoint, symbol_size=50, label_opts=opts.LabelOpts(formatter=operator) ), markline_opts=opts.MarkLineOpts( data=makeline, label_opts=opts.LabelOpts(formatter=operator+":{c}") ) ) line.set_global_opts( datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside")], yaxis_opts=opts.AxisOpts(min_=int(min(y)-(max(y)-min(y))/10),name=y_name,axislabel_opts=opts.LabelOpts(font_size="100%"),name_textstyle_opts=opts.TextStyleOpts(font_size="100%")), legend_opts=opts.LegendOpts(is_show=False), xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=40,font_size='100%'),name=x_name,name_textstyle_opts=opts.TextStyleOpts(font_size="100%")), graphic_opts=[opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=['\n' + "Q:" + ' ' + query + '\n' +"\n"+ 'A:' + ' ' + answer], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333" ) ) )] ) grid = Grid( init_opts=opts.InitOpts( width="100%", height="100%", renderer= globals.RenderType.SVG, )) grid.add(line, grid_opts={'left':'20%','bottom':'34%'}) # grid1=Grid() # grid1.add(line, grid_opts={'left':'20%','bottom':'34%'}) # grid1.render("MAX.html") option1=grid.dump_options_with_quotes() option1=json.loads(option1) option={"option":[option1],"query":query} return option
def bar_base() -> Line: bar = ( Bar() .set_global_opts( title_opts=opts.TitleOpts(title=""), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( # 控制整体的位置 left="5%", top="10%", ), children=[ # opts.GraphicRect控制方框的显示 # 如果不需要方框,去掉该段即可 opts.GraphicRect( graphic_item=opts.GraphicItem( z=100, left="center", top="middle", ), graphic_shape_opts=opts.GraphicShapeOpts( width=800, height=400, ), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff", stroke="#555", line_width=2, shadow_blur=8, shadow_offset_x=3, shadow_offset_y=3, shadow_color="rgba(0,0,0,0.3)", ) ), # opts.GraphicText控制文字的显示 opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="middle", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=JsCode( "['根据世界银行(World Bank)统计数据, '," "' '," "'亚洲地区在近十几年来,有着越来越多的国家增加高科技的出口,并且大体上呈现逐年增加的趋势。'," "' '," "' '," "'欧洲地区,随着大多数经济体的衰落或者停滞不前,'," "' '," "'欧洲各地的高科技出口都难以取得进展,但仍然处于世界高科技出口的中上行列。'," "' '," "' '," "'北美洲,得益于美国加拿大等强国,一直都保持的稳定的高科技出口。'," "' '," "' '," "'南美洲,在金融危机之后,开始出现了高科技出口,并且也是大体上呈现高科技出口国家逐年增加的趋势;'," "' '," "' '," "'非洲地区是目前世界上高科技出口水平较弱的地区,近十几年来无明显变化趋势,处于世界高科技出口的下游,水平有待加强。'," "' '," "' '," "'说明经济的不确定性对世界的发展状况息息相关,国际政治格局和贸易关系迅速变化导致全球市场高度不确定,'," "' '," "'在这样的十几年里,制度的质量似乎是促进繁荣的重要因素。'," "' '," "'强有力的制度框架为企业投资和创新提供了稳定性,确保了公民更高的生活质量。'].join('\\n')" ), font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333" ) ) ) ] ) ], ) ) return bar
def bmap_custom() -> BMap: with open( os.path.join("fixtures", "bmap-custom-data.json"), "r", encoding="utf-8" ) as f: j = json.load(f) color_list = ["#070093", "#1c3fbf", "#1482e5", "#70b4eb", "#b4e0f3", "#ffffff"] c = ( BMap() .add_schema( baidu_ak=BAIDU_MAP_AK, center=[116.46, 39.92], zoom=11.8, is_roam=True, map_style={ "styleJson": [ { "featureType": "water", "elementType": "all", "stylers": {"color": "#d1d1d1"}, }, { "featureType": "land", "elementType": "all", "stylers": {"color": "#f3f3f3"}, }, { "featureType": "railway", "elementType": "all", "stylers": {"visibility": "off"}, }, { "featureType": "highway", "elementType": "all", "stylers": {"color": "#999999"}, }, { "featureType": "highway", "elementType": "labels", "stylers": {"visibility": "off"}, }, { "featureType": "arterial", "elementType": "geometry", "stylers": {"color": "#fefefe"}, }, { "featureType": "arterial", "elementType": "geometry.fill", "stylers": {"color": "#fefefe"}, }, { "featureType": "poi", "elementType": "all", "stylers": {"visibility": "off"}, }, { "featureType": "green", "elementType": "all", "stylers": {"visibility": "off"}, }, { "featureType": "subway", "elementType": "all", "stylers": {"visibility": "off"}, }, { "featureType": "manmade", "elementType": "all", "stylers": {"color": "#d1d1d1"}, }, { "featureType": "local", "elementType": "all", "stylers": {"color": "#d1d1d1"}, }, { "featureType": "arterial", "elementType": "labels", "stylers": {"visibility": "off"}, }, { "featureType": "boundary", "elementType": "all", "stylers": {"color": "#fefefe"}, }, { "featureType": "building", "elementType": "all", "stylers": {"color": "#d1d1d1"}, }, { "featureType": "label", "elementType": "labels.text.fill", "stylers": {"color": "rgba(0,0,0,0)"}, }, ] }, ) .add_js_funcs( """ var lngExtent = [39.5, 40.6]; var latExtent = [115.9, 116.8]; var cellCount = [50, 50]; var cellSizeCoord = [ (lngExtent[1] - lngExtent[0]) / cellCount[0], (latExtent[1] - latExtent[0]) / cellCount[1] ]; var gapSize = 0; function renderItem(params, api) { var lngIndex = api.value(0); var latIndex = api.value(1); var pointLeftTop = getCoord(params, api, lngIndex, latIndex); var pointRightBottom = getCoord(params, api, lngIndex + 1, latIndex + 1); return { type: 'rect', shape: { x: pointLeftTop[0], y: pointLeftTop[1], width: pointRightBottom[0] - pointLeftTop[0], height: pointRightBottom[1] - pointLeftTop[1] }, style: api.style({ stroke: 'rgba(0,0,0,0.1)' }), styleEmphasis: api.styleEmphasis() }; } function getCoord(params, api, lngIndex, latIndex) { var coords = params.context.coords || (params.context.coords = []); var key = lngIndex + '-' + latIndex; return coords[key] || (coords[key] = api.coord([ +(latExtent[0] + lngIndex * cellSizeCoord[0]).toFixed(6), +(lngExtent[0] + latIndex * cellSizeCoord[1]).toFixed(6) ])); } """ ) .add( series_name="", data_pair=j["data"], type_=ChartType.CUSTOM, render_item=JsCode("renderItem"), itemstyle_opts=opts.ItemStyleOpts(color="yellow"), encode={"tooltip": 2}, ) .set_global_opts( title_opts=opts.TitleOpts(title="BMap-Custom 图"), tooltip_opts=opts.TooltipOpts(is_show=True, formatter=None), visualmap_opts=opts.VisualMapOpts( is_piecewise=True, pos_top="10", pos_left="10", is_inverse=True, pieces=[ {"value": i, "color": color_list[i]} for i in range(len(color_list)) ], dimension=2, border_color="#ccc", border_width=2, background_color="#eee", range_opacity=0.7, ), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( rotation=JsCode("Math.PI / 4"), bounding="raw", right=110, bottom=110, z=100, ), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem( left="center", top="center", z=100 ), graphic_shape_opts=opts.GraphicShapeOpts( width=400, height=50 ), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)" ), ), opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="center", z=100 ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( text="Made by pyecharts", font="bold 26px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff" ), ), ), ], ) ], ) ) return c
axislabel_opts=opts.LabelOpts( is_show=True, # 显示标签 position='top', # 标签位置 formatter='{value}', # 轴上的数值显示 )), # 设置提示框的类型 tooltip_opts=opts.TooltipOpts( trigger='axis', # 进入坐标轴,就触发提示框 trigger_on='mousemove|click', # 点击或者鼠标移动都触发提示 axis_pointer_type='cross', # 指示器类型, cross ---十字准星 ), # 文本设置 ---借助原生组件元素设置 graphic_opts=opts.GraphicGroup( # 控制文本相对于整体的位置 graphic_item=opts.GraphicItem( # left='80%', top='45%'), # 设置文本 children=[ # # 设置文本框 # opts.GraphicRect( # # ), # 设置文本 opts.GraphicText( # 配置的文本相对于 --->文本框的位置 graphic_item=opts.GraphicItem( left='center', # 文本相对于文本框的左位置 top='middle', # 文本相对文本框的上位置 z=100, # 字在文本框的z轴方向100的位置 scale=[1.3, 1.5], # [横向缩放的倍数, 纵向缩放的倍数]
def find_proportion_render(x, y, z, part_name, main_name, query, table_path, answer): x = list(map(str, x)) y = list(map(float, y)) z = list(map(float, z)) colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff'] y_part = [] y_main = [] for i in range(len(y)): percentage = y[i] / z[i] * 100 percentage = str(percentage).split('.')[0] + '.' + str( percentage).split('.')[1][:2] y_part.append( opts.BarItem( name=x[i], value=y[i], label_opts=opts.LabelOpts(position="insideTop", formatter=str(percentage) + "%"), itemstyle_opts=opts.ItemStyleOpts(color=colorList[2]))) y_main.append(opts.BarItem( name=x[i], value=z[i] - y[i], )) bar = Bar() bar.add_xaxis(x) bar.add_yaxis('', y_axis=y_part, stack='stack1', label_opts=opts.LabelOpts(position="insideTop"), itemstyle_opts=opts.ItemStyleOpts(color=colorList[2]), tooltip_opts=opts.TooltipOpts(formatter=part_name + ':{c}')), bar.add_yaxis('', y_axis=y_main, stack='stack1', label_opts=opts.LabelOpts(is_show=False), color="gray", tooltip_opts=opts.TooltipOpts(formatter=main_name + ':{c}')) bar.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], legend_opts=opts.LegendOpts(is_show=False), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) bar.render("aggregation.html") grid = Grid(init_opts=opts.InitOpts( width="100%", height="100%", renderer=globals.RenderType.SVG, )) grid.add(bar, grid_opts={'left': '20%', 'bottom': '34%'}) option1 = grid.dump_options_with_quotes() option1 = json.loads(option1) option = {"option": [option1], "query": query} return option
def find_aggregation_render(x, y, flag, query, table_path, answer, y_name): colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff'] x_sum = ["Sum"] Sum = [] Sum.append(sum(y)) mean = np.mean(y) y1 = [] y2 = [] for i in range(len(y)): if y[i] >= mean: y1.append(round(mean, 2)) y2.append( opts.BarItem(name=x[i], value=round(y[i] - mean, 2), label_opts=opts.LabelOpts(formatter="+{c}"), itemstyle_opts=opts.ItemStyleOpts(color="red"))) else: y1.append(round(y[i], 2)) y2.append( opts.BarItem(name=x[i], value=round(mean - y[i], 2), label_opts=opts.LabelOpts(formatter="-{c}"), itemstyle_opts=opts.ItemStyleOpts(color="green", opacity=0.3))) if flag == "mean": bar = Bar() bar.add_xaxis(x) bar.add_yaxis( '', y_axis=y1, stack='stack1', label_opts=opts.LabelOpts(is_show=False), color="white", markline_opts=opts.MarkLineOpts( data=[opts.MarkLineItem(name="mean:", y=round(mean, 2))], label_opts=opts.LabelOpts(formatter="Mean:{c}", color="black"), linestyle_opts=opts.LineStyleOpts(color="gray")), ) bar.add_yaxis('', y_axis=y2, stack='stack1') bar.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside") ], xaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts(rotate=40, font_size='100%'), name_textstyle_opts=opts.TextStyleOpts(font_size="100%")), yaxis_opts=opts.AxisOpts( min_=int(min(y) - (max(y) - min(y)) / 10), name=y_name, axislabel_opts=opts.LabelOpts(font_size="100%"), name_textstyle_opts=opts.TextStyleOpts(font_size="100%")), graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + "\n" + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) bar.render("aggregation.html") grid = Grid(init_opts=opts.InitOpts( width="100%", height="100%", renderer=globals.RenderType.SVG, )) grid.add(bar, grid_opts={'left': '15%', 'bottom': '34%'}) grid1 = Grid() grid1.add(bar, grid_opts={'left': '15%', 'bottom': '34%'}) grid1.render("mean.html") option1 = grid.dump_options_with_quotes() option1 = json.loads(option1) option = {"option": [option1], "query": query} return option elif flag == "sum": bar = Bar() bar.add_xaxis(x_sum) bar.add_yaxis('', Sum, label_opts=opts.LabelOpts(position="inside", formatter="Sum:{c}"), color=colorList[0]) for i in range(len(y)): Y = [] Y.append(y[i]) r = str(x[i]) bar.add_yaxis('', Y, stack='stack1', label_opts=opts.LabelOpts(position="inside", formatter=r + ":{c}"), tooltip_opts=opts.TooltipOpts(is_show=False)) bar.set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=10, range_end=90, orient="vertical"), opts.DataZoomOpts(type_="inside") ], graphic_opts=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=[ '\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer ], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333"))) ]) grid = Grid(init_opts=opts.InitOpts( width="100%", height="100%", renderer=globals.RenderType.SVG, )) grid.add(bar, grid_opts={'left': '15%', 'bottom': '34%'}) option1 = grid.dump_options_with_quotes() option1 = json.loads(option1) option = {"option": [option1], "query": query} return option
max_=30000, # 轴线的配置 axisline_opts=opts.AxisLineOpts( is_show=True, # 轴线风格 linestyle_opts=opts.LineStyleOpts(color='#fd5956')), # 轴线对应标签的数据 {value} 数据 axislabel_opts=opts.LabelOpts(formatter='{value}')), # 插入文本框 graphic_opts=opts.GraphicGroup( # 图形配置 graphic_item=opts.GraphicItem( # 控制整体的位置 left='75%', top='45%', ), children=[ # GraphicRect控制方框的显示 # opts.GraphicRect( # graphic_item=opts.GraphicItem( # z=100, # 文本的高度 # left='center', # top='middle', # ), # graphic_shape_opts=opts.GraphicShapeOpts( # width=420, # 宽度 # height=180, # 高度 # ), # graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
c = ( Bar().add_xaxis(Faker.choose()).add_yaxis("商家A", Faker.values()). add_yaxis("商家B", Faker.values()).set_global_opts( title_opts=opts.TitleOpts(title="Bar-Graphic 组件示例"), #组件配置 graphic_opts=[ #原生组件配置 opts.GraphicGroup( # 图形的配置项 #原生图形配置项 graphic_item=opts.GraphicItem( #旋转(rotation):默认值是 0。表示旋转的弧度值。正值表示逆时针旋转 rotation=JsCode("Math.PI / 4"), # 决定此图形元素在定位时,对自身的包围盒计算方式 bounding="raw", #描述怎么根据父元素进行定位。 right=110, bottom=110, z=100, ), children=[ #原生图形矩形配置项 opts.GraphicRect( #graphic_item:图形的配置项 #GraphicItem:原生图形配置项 graphic_item=opts.GraphicItem( #left:描述怎么根据父元素进行定位。 top :配置和 left 及 right 相同 z 方向的高度,决定层叠关系。 left="center", top="center", z=100), # 图形的形状配置项,
def draw_rose_piture(self,my_rose_data): total_position = 0 for x in my_rose_data: total_position = total_position + x[1] #print(total_position) if os.path.isfile('pie_rosetype.html'): os.remove('.\pie_rosetype.html') c = ( Pie() .add( "", my_rose_data, radius=["30%", "75%"], #center=["25%", "50%"], rosetype="radius", #label_opts=opts.LabelOpts(is_show=False), ) #.add( # "", # my_rose_data, # radius=["30%", "75%"], # center=["75%", "50%"], # rosetype="area", #) .set_global_opts( title_opts=opts.TitleOpts(title="Positions",pos_left="8%",pos_top="8%"), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( # 控制整体的位置 right="15%", bottom="5%", ), children=[ # opts.GraphicRect控制方框的显示 # 如果不需要方框,去掉该段即可 #opts.GraphicRect( # graphic_item=opts.GraphicItem( # z=100, # right="center", # bottom="middle", # ), # graphic_shape_opts=opts.GraphicShapeOpts( # width=120, height=70, # ), # graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( # fill="#fff", # stroke="#555", # line_width=2, # shadow_blur=8, # shadow_offset_x=3, # shadow_offset_y=3, # shadow_color="rgba(144,238,144,0.3)", # ) #), # opts.GraphicText控制文字的显示 opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="middle", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text="Total:"+str(total_position)+"%", font="bolder 21px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#C537B6" ) ) ) ] ) ] ) .set_series_opts(label_opts=opts.LabelOpts(formatter="{b} {c}%")) .render("pie_rosetype.html") )
def line_base() -> Line: bar = ( Bar() .set_global_opts( title_opts=opts.TitleOpts(title=""), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( # 控制整体的位置 left="5%", top="10%", ), children=[ # opts.GraphicRect控制方框的显示 # 如果不需要方框,去掉该段即可 opts.GraphicRect( graphic_item=opts.GraphicItem( z=100, left="center", top="middle", ), graphic_shape_opts=opts.GraphicShapeOpts( width=800, height=400, ), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff", stroke="#555", line_width=2, shadow_blur=8, shadow_offset_x=3, shadow_offset_y=3, shadow_color="rgba(0,0,0,0.3)", ) ), # opts.GraphicText控制文字的显示 opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="middle", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=JsCode( "['根据世界银行(World Bank)统计数据: '," "' '," "'2007-2009年中,新加坡、马耳他、冰岛以及哥斯达黎加等国,位列世界高科技出口的前列,高科技出口数量远超其他国家。'," "' '," "' '," "'2010-2014年中,随着各国家的发展,越来越多的国家开始出口高科技,比如马来西亚,格陵兰岛,尼日尔、哈萨克斯坦等国家,'," "' '," "'开始增加自己的高科技出口,在世界高科技出口中开始崭露头角。'," "' '," "' '," "'2015-2018年中,高科技出口的前列国家变化很大,有塞舌尔,阿拉伯联合酋长国,百慕大群岛等国的昙花一现,'," "' '," "'也有帕劳共和国以及菲律宾等国经久不衰,世界高科技出口的国家朝着多极化方向发展。'," "' '," "' '," "'表明近十几年来,世界各国都认识到了高科技出口的重要性,'," "' '," "' '," "'开始利用先进的技术基础设施、商业政策环境以及获得商业融资渠道的便利性等因素,'," "' '," "'出口本国的高科技产品,以增加国家在世界上的竞争力。'].join('\\n')" ), font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333" ) ) ) ] ) ], ) ) return bar
from pyecharts import options as opts from pyecharts.charts import Bar, Grid from pyecharts.faker import Faker bar = (Bar(init_opts=opts.InitOpts(chart_id="1234")).add_xaxis(Faker.choose( )).add_yaxis("商家A", Faker.values()).add_yaxis( "商家B", Faker.values()).set_global_opts( title_opts=opts.TitleOpts(title="Bar-Graphic Image(旋转功能)组件示例"), graphic_opts=[ opts.GraphicImage( graphic_item=opts.GraphicItem(id_="logo", right=20, top=20, z=-10, bounding="raw", origin=[75, 75]), graphic_imagestyle_opts=opts.GraphicImageStyleOpts( image="https://www.echartsjs.com/zh/images/favicon.png", width=150, height=150, opacity=0.4, ), ) ], )) c = (Grid(init_opts=opts.InitOpts(chart_id="1234")).add( chart=bar, grid_opts=opts.GridOpts(pos_left="5%", pos_right="4%", pos_bottom="5%"), ).add_js_funcs(""" var rotation = 0; setInterval(function () {
def grid_horizontal1() -> Grid: bar1 = ( Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)) .add_xaxis(['南亚', '撒哈拉以南非洲地区(不包括高收入)', '欧洲与中亚地区(不包括高收入)', '拉丁美洲与加勒比海地区(不包括高收入)', '东亚与太平洋地区(不包括高收入)', '中东与北非地区(不包括高收入)']) .add_yaxis("Region", [Region.count('南亚'), Region.count('撒哈拉以南非洲地区(不包括高收入)'), Region.count('欧洲与中亚地区(不包括高收入)'), Region.count('拉丁美洲与加勒比海地区(不包括高收入)'), Region.count('东亚与太平洋地区(不包括高收入)'), Region.count('中东与北非地区(不包括高收入)')]) .set_global_opts(title_opts=opts.TitleOpts(title="Region", subtitle="2019", pos_left="2%"), legend_opts=opts.LegendOpts(pos_left="20%")) ) bar = ( Bar() .set_global_opts( title_opts=opts.TitleOpts(title=""), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( # 控制整体的位置 left="52%", top="7%", ), children=[ # opts.GraphicRect控制方框的显示 # 如果不需要方框,去掉该段即可 opts.GraphicRect( graphic_item=opts.GraphicItem( z=100, left="center", top="middle", ), graphic_shape_opts=opts.GraphicShapeOpts( width=400, height=440, ), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#fff", stroke="#555", line_width=2, shadow_blur=8, shadow_offset_x=3, shadow_offset_y=3, shadow_color="rgba(0,0,0,0.3)", ) ), # opts.GraphicText控制文字的显示 opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="middle", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=JsCode( "['根据世界银行(World Bank)统计数据, '," "'南亚有8个国家、'," "'撒哈拉以南非洲地区有48个国家、'," "'欧洲与中亚地区有58个国家、'," "'拉丁美洲与加勒比海地区有42个国家、'," "'东亚与太平洋地区有37个国家、'," "'中东与北非地区有21个国家。'," "' '," "'此图除去了世界高收入国家,'," "'南亚8个国家、撒哈拉以南非洲地区47个国家、'," "'欧洲与中亚地区有21个国家、'," "'拉丁美洲与加勒比海地区有25个国家、'," "'东亚与太平洋地区有24个国家、'," "'中东与北非地区有13个国家不属于高收入国家。'," "' '," "'各地区高收入国家占比分别为(四舍五入取整):'," "'南亚0%、撒哈拉以南非洲地区98%、'," "'欧洲与中亚地区36%、'," "'拉丁美洲与加勒比海地区60%、'," "'东亚与太平洋地区65%、'," "'中东与北非地区62%'," "' '," "'收入与生活水平有一定联系。'," "'就各地区高收入国家占比,'," "'可对各地区生活水平做出以下排序(高到低):'," "'撒哈拉以南非洲地区>东亚与太平洋地区>'," "'中东与北非地区>拉丁美洲与加勒比海地区>'," "'欧洲与中亚地区>南亚'].join('\\n')" ), font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333" ) ) ) ] ) ], ) ) grid1 = ( Grid() .add(bar, grid_opts=opts.GridOpts(pos_left="55%")) .add(bar1, grid_opts=opts.GridOpts(pos_right="55%")) ) return grid1
def line_render_qimai(self): c = Line(init_opts=opts.InitOpts(width="1200px", height="400px")) # c = Line() c.add_xaxis(self.x_value) c.add_yaxis( series_name=self.y_name, y_axis=self.y_value, is_symbol_show=self.is_symbol_show, # 线上不用点标记 color=self.color_list[0], linestyle_opts=opts.LineStyleOpts(width=self.line_width), # 线条加粗 label_opts=opts.LabelOpts(is_show=self.is_show)) c.set_global_opts( title_opts=opts.TitleOpts( title=self.title, pos_top="2%", # 距离顶层2% pos_left="center", title_textstyle_opts=opts.TextStyleOpts( color="#666", font_size=16, font_weight='normal', font_family='Microsoft YaHei'), ), tooltip_opts=opts.TooltipOpts(trigger="axis"), # legend_opts=opts.LegendOpts(pos_left="center", pos_top=self.pos_top, legend_icon='circle'), legend_opts=opts.LegendOpts(pos_left="center", pos_top='bottom', legend_icon='circle'), yaxis_opts=opts.AxisOpts( type_="value", max_=self.y_max, min_=self.y_min, is_inverse=self.y_is_inverse, # 反向Y轴; boundary_gap=self.boundary_gap, # 封闭坐标轴,左右都有顶上的刻度线; axislabel_opts=opts.LabelOpts(color="#7D7D7D"), axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(width=1.5, color="#A0A7B3")), axistick_opts=opts.AxisTickOpts(is_show=True, is_inside=True), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts( color="#E2E2E2")), # 设置网格线; ), xaxis_opts=opts.AxisOpts( type_="category", min_=self.x_min, boundary_gap=self.boundary_gap, is_inverse=self.x_is_inverse, # 反向X轴; axislabel_opts=opts.LabelOpts(color="#7D7D7D"), axisline_opts=opts.AxisLineOpts( linestyle_opts=opts.LineStyleOpts(width=1.5, color="#A0A7B3")), axistick_opts=opts.AxisTickOpts(is_show=True, is_inside=True), splitline_opts=opts.SplitLineOpts( is_show=True, linestyle_opts=opts.LineStyleOpts(color="#E2E2E2")), ), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( rotation=JsCode("Math.PI / 500"), bounding="raw", right=700, bottom=150, z=100, ), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_shape_opts=opts.GraphicShapeOpts( width=400, height=50), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0)"), ), opts.GraphicText( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_textstyle_opts=opts.GraphicTextStyleOpts( text="七麦数据", # font="bold 26px Microsoft YaHei", font="26px Microsoft YaHei", graphic_basicstyle_opts=opts. GraphicBasicStyleOpts(fill="#D5D5D5"), ), ), ], ) ], # 下方为图片水印代码; # graphic_opts=[ # opts.GraphicImage( # graphic_item=opts.GraphicItem( # id_="logo", # left='142', # z='10', # # 距离上边界距离 # top='340', # # 负数则显示在图表下层 # z_level=-1 # ), # graphic_imagestyle_opts=opts.GraphicImageStyleOpts( # # 指定图片地址,最好选用png # image="https://tva1.sinaimg.cn/large/008eGmZEly1gmfcjqkwrkj302q00mq2q.jpg", # # 长设置 # width=100, # height=23, # opacity=1, # ), # ), # ] ) # 插入其他y线条; if len(self.args) > 0: for num in range(len(self.args[0])): if num + 1 > len(self.color_list) - 1: color_str = '' else: color_str = self.color_list[num + 1] c.add_yaxis( series_name=self.args[0][num], y_axis=self.args[1][num], is_symbol_show=self.is_symbol_show, # 线上不用点标记 color=color_str, linestyle_opts=opts.LineStyleOpts( width=self.line_width), # 线条加粗 label_opts=opts.LabelOpts(is_show=self.is_show), ) self.c_render = c return c
legend_opts=opts.LegendOpts(pos_top="5%", is_show=True)) wc_tl = Timeline(init_opts=opts.InitOpts(width="1200px", height="600px")) idx = 0 for date, tmp_data in wc_data: wc = WordCloud() wc.add(series_name="", data_pair=tmp_data) wc.set_global_opts( title_opts=opts.TitleOpts(title="词频统计", pos_top="top", pos_left="center"), tooltip_opts=opts.TooltipOpts(is_show=True), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem(right="0%", top="0%"), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem(z=500, left="center", top="middle"), graphic_shape_opts=opts.GraphicShapeOpts( width=280, height=130), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)", #stroke="#555", line_width=2, shadow_blur=8, shadow_offset_x=3, shadow_offset_y=3, shadow_color="rgba(0,0,0,0.3)",
from pyecharts import options as opts from pyecharts.charts import Bar from pyecharts.commons.utils import JsCode from pyecharts.faker import Faker c = (Bar().add_xaxis(Faker.choose()).add_yaxis( "商家A", Faker.values()).add_yaxis("商家B", Faker.values()).set_global_opts( title_opts=opts.TitleOpts(title="Bar-Graphic Rect+Text 1 组件示例"), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( rotation=JsCode("Math.PI / 4"), bounding="raw", right=110, bottom=110, z=100, ), children=[ opts.GraphicRect( graphic_item=opts.GraphicItem(left="center", top="center", z=100), graphic_shape_opts=opts.GraphicShapeOpts(width=400, height=50), graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)"), ), opts.GraphicText( graphic_item=opts.GraphicItem(left="center", top="center", z=100),
def find_distribution_render(x,Y,x_name,query,table_path,answer): Max=0 y=[] data=[] label=[] boxplot = Boxplot() boxplot.add_xaxis(xaxis_data=label) for i in range(len(Y)): data.append(Y[i][1]) label.append(Y[i][0]) # boxplot.add_yaxis(series_name=Y[i][0],y_axis=boxplot.prepare_data(data)) for j in Y[i][1]: y.append(j) boxplot.add_yaxis(series_name="", y_axis=boxplot.prepare_data(data)) boxplot.set_global_opts( yaxis_opts=opts.AxisOpts(name="Distribution",axislabel_opts=opts.LabelOpts(font_size="100%"),name_textstyle_opts=opts.TextStyleOpts(font_size="100%")), legend_opts=opts.LegendOpts(is_show=False), xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=40,interval=0,font_size='100%'),name="Category",name_textstyle_opts=opts.TextStyleOpts(font_size="100%")), graphic_opts=[opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", z=100, ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=['\n' + "Q:" + ' ' + query + '\n'+"\n" + 'A:' + ' ' + answer], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333" ) ) )] ) bar=Bar({"theme": ThemeType.MACARONS}) bar.add_xaxis(xaxis_data=x) for i in range(len(Y)): max_index, max_number = max(enumerate(Y[i][1]), key=operator.itemgetter(1)) min_index, min_number = min(enumerate(Y[i][1]), key=operator.itemgetter(1)) if max_number>Max: Max=max_number bar.add_yaxis(Y[i][0],label_opts=opts.LabelOpts(is_show=False),y_axis=Y[i][1],markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(coord=[max_index,max_number*1.01],value="MAX",name="最大值",itemstyle_opts=opts.ItemStyleOpts(opacity=0.6)),opts.MarkPointItem(coord=[min_index,min_number*1.05],value="MIN",name="最小值",itemstyle_opts=opts.ItemStyleOpts(opacity=0.6))] ), markline_opts=opts.MarkLineOpts( data=[opts.MarkLineItem(type_="average",name="平均值")] )) bar.set_global_opts( datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside")], yaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts(font_size="100%"), name_textstyle_opts=opts.TextStyleOpts(font_size="100%")), xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=40, interval=0, font_size='100%'), name=x_name, name_textstyle_opts=opts.TextStyleOpts(font_size="100%")), graphic_opts=[opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=['\n' + "Q:" + ' ' + query + '\n' + "\n"+'A:' + ' ' + answer], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333" ) ) )] ) grid = Grid( init_opts=opts.InitOpts( width="100%", height="100%", renderer= globals.RenderType.SVG,)) grid.add(boxplot, grid_opts={'left':'20%','bottom':'34%'}) grid1 = Grid( init_opts=opts.InitOpts( width="100%", height="100%", renderer= globals.RenderType.SVG,)) grid1.add(bar,grid_opts={'left':'20%','bottom':'34%'}) option1=grid.dump_options_with_quotes() option1=json.loads(option1) option2=grid1.dump_options_with_quotes() option2=json.loads(option2) option={"option":[option1,option2],"query":query} return option
def TREND_render(x,y,z,y_up,y_down,max_index,min_index,x_name,y_name,query,answer): x=list(map(str,x)) y=list(map(float,y)) bar = ( Bar() .add_xaxis(xaxis_data=x) .add_yaxis( series_name="increase_value", y_axis=y_up, markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_='max')] ), ) # .add_yaxis(series_name="increase", yaxis_data=y_up, stack="GDP",markpoint_opts=opts.MarkPointOpts( # data=[opts.MarkPointItem(name=x[max_index], coord=[x[max_index], y[max_index]+y_up[max_index]+z[max_index]], value="Max")] # ),) .add_yaxis(series_name="decrease_value", y_axis=y_down, stack="GDP",markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_='max')] ),) .set_global_opts( datazoom_opts=[opts.DataZoomOpts(range_start=10, range_end=90), opts.DataZoomOpts(type_="inside")], yaxis_opts=opts.AxisOpts( name=y_name, type_="value", axislabel_opts=opts.LabelOpts(formatter="{value}"), axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), xaxis_opts=opts.AxisOpts(name=x_name), graphic_opts=[opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="bottom", ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( # 可以通过jsCode添加js代码,也可以直接用字符串 text=['\n'+"Q:"+' '+query+'\n'+"\n"+'A:'+' '+answer], font="14px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="#333" ) ) )] ) ) line = ( Line() .add_xaxis(xaxis_data=x) .add_yaxis( series_name='food', yaxis_index=0, y_axis=y, label_opts=opts.LabelOpts(is_show=True), # markpoint_opts=opts.MarkPointOpts( # data=[opts.MarkPointItem(type_='max', value='Max'),opts.MarkPointItem(type_='min',value='Max')], # ), ) .set_global_opts(legend_opts=opts.LegendOpts(is_show=False), ) ) # line.overlap(bar).render("TREND.html") grid = Grid(init_opts=opts.InitOpts( width="100%", height="100%", renderer=globals.RenderType.SVG, )) grid.add(bar.overlap(line), grid_opts={'left': '20%', 'bottom': '34%'}) option1 = grid.dump_options_with_quotes() option1 = json.loads(option1) option = {"option": [option1], "query": query} return option
def generate_html(self): df = self.get_bond_data() data = self.get_XY_data(df) bigger = data['bigger'] smaller = data['smaller'] avg = data['avg'] std = data['std'] max_name = data['max_name'] max_pct = data['max_pct'] min_name = data['min_name'] min_pct = data['min_pct'] bar = (Bar().add_xaxis(list(data['result_dict'].keys())).add_yaxis( f"{self.today}-可转债价格分布", data['zz_list'], category_gap=3).add_yaxis( f"{self.today}-正股价格分布", data['zg_list'], category_gap=3).set_series_opts( label_opts=opts.LabelOpts(is_show=True), axispointer_opts=opts.AxisPointerOpts(is_show=True)). set_global_opts( title_opts=opts.TitleOpts(title="可转债价格分布"), xaxis_opts=opts.AxisOpts( name="涨跌幅", is_show=True, name_rotate=30, ), graphic_opts=[ opts.GraphicGroup( graphic_item=opts.GraphicItem( left="70%", top="20%", ), children=[ opts.GraphicText( graphic_item=opts.GraphicItem( left="center", top="middle", z=100, ), graphic_textstyle_opts=opts. GraphicTextStyleOpts( text=JsCode( f"['涨幅>=0:{bigger}'," f"'涨幅<0:{smaller}'," f"'平均涨幅:{avg}%'," f"'波动方差:{std}'," f"''," f"'最大:{max_name} {max_pct}%'," f"'最小:{min_name} {min_pct}%'," "''].join('\\n')"), font="14px Microsoft YaHei", graphic_basicstyle_opts=opts. GraphicBasicStyleOpts(fill="#333"))) ]) ], )) bar.render(self.HMTL_PATH) # 自定义一个driver make_snapshot(snapshot, bar.render(), self.IMGAGE_PATH, driver=driver)