def drawer2(stage_name, data): c_schema = [ { "name": "乐", "max": 0.55, "min": 0 }, { "name": "好", "max": 0.55, "min": 0 }, { "name": "哀", "max": 0.55, "min": 0 }, { "name": '恶', "max": 0.55, "min": 0 }, { "name": "惧", "max": 0.55, "min": 0 }, ] c = (Radar().set_colors(["#CC3300"]).add_schema( schema=c_schema, shape="circle", center=["50%", "50%"], radius="80%", angleaxis_opts=opts.AngleAxisOpts( min_=0, max_=360, is_clockwise=False, interval=5, axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=False), ), radiusaxis_opts=opts.RadiusAxisOpts( min_=-4, max_=4, interval=2, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), polar_opts=opts.PolarOpts(), splitarea_opt=opts.SplitAreaOpts(is_show=False), splitline_opt=opts.SplitLineOpts(is_show=False), ).add( series_name=stage_name, data=data, areastyle_opts=opts.AreaStyleOpts(opacity=0.1), linestyle_opts=opts.LineStyleOpts(width=3), ).render("res\\output\\multi-emotion\\image\\" + stage_name + ".html"))
def polar_radiusaxis() -> Polar: c = (Polar().add_schema( radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week, type_="category"), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=10), ).add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar").set_global_opts( title_opts=opts.TitleOpts(title="Polar-RadiusAxis")).set_series_opts( label_opts=opts.LabelOpts(is_show=True))) return c
def polar_radiusaxis() -> Polar: c = (Polar().add_schema(radiusaxis_opts=opts.RadiusAxisOpts( data=Faker.week, type_="category")).add( "A", [1, 2, 3, 4, 3, 5, 1], type_="bar", stack="stack0").add( "B", [2, 4, 6, 1, 2, 3, 1], type_="bar", stack="stack0").add( "C", [1, 2, 3, 4, 1, 2, 5], type_="bar", stack="stack0").set_global_opts(title_opts=opts.TitleOpts( title="Polar-RadiusAxis"))) return c
def po_base(): d = (Polar().add_schema(radiusaxis_opts=opts.RadiusAxisOpts( data=Faker.week, type_="category")).add( "休息时间", [9, 9, 9, 9, 10, 5, 10], type_="bar", stack="stack0").add( "有效提升时间", [2, 2, 3, 1, 2, 1, 2], type_="bar", stack="stack0").add( "浪费时间", [3, 2, 3, 4, 6, 8, 5], type_="bar", stack="stack0").set_global_opts(title_opts=opts.TitleOpts( title="Polar-RadiusAxis"))) return d
def test_radar_options(fake_writer): c = (Radar().add_schema( schema=[ opts.RadarIndicatorItem(name="销售", max_=6500), opts.RadarIndicatorItem(name="管理", max_=16000), opts.RadarIndicatorItem(name="信息技术", max_=30000), opts.RadarIndicatorItem(name="客服", max_=38000), opts.RadarIndicatorItem(name="研发", max_=52000), opts.RadarIndicatorItem(name="市场", max_=25000), ], radiusaxis_opts=opts.RadiusAxisOpts(), angleaxis_opts=opts.AngleAxisOpts(), polar_opts=opts.PolarOpts(), ).add("预算分配", v1).add( "实际开销", v2).set_series_opts(label_opts=opts.LabelOpts(is_show=False))) c.render() _, content = fake_writer.call_args[0] assert_in("radiusAxis", content) assert_in("angleAxis", content) assert_in("polar", content)
def Radar_pic(name, datas, ifratio) -> Radar: color = ["#ff7f00"] if ifratio else ["#4587E7"] data = [{"value": datas, "name": name}] watermax = 1000 if datas[0] < 1000 else datas[0] * 1.1 mountainmax = 1000 if datas[1] < 1000 else datas[1] * 1.1 corridormax = 1000 if datas[2] < 1000 else datas[2] * 1.1 secondmax = 250 if datas[3] < 250 else datas[3] * 1.1 intermax = 500 if datas[4] < 500 else datas[4] * 1.1 landscapemax = 250 if datas[5] < 250 else datas[5] * 1.1 mainmax = 250 if datas[6] < 250 else datas[6] * 1.1 othermax = 450 if datas[7] < 450 else datas[7] * 1.1 waterratio = 0.25 if datas[0] < 0.25 else datas[0] * 1.2 mountainratio = 0.25 if datas[1] < 0.25 else datas[1] * 1.1 c_schema = [ { "name": "主水", "max": round(waterratio, 2) if ifratio else round(watermax) }, { "name": "主山", "max": round(mountainratio, 2) if ifratio else round(mountainmax) }, { "name": "廊道", "max": 0.25 if ifratio else round(corridormax) }, { "name": "次路", "max": 0.20 if ifratio else round(secondmax) }, { "name": "夹层", "max": 0.20 if ifratio else round(intermax) }, { "name": "主景观建筑", "max": 0.20 if ifratio else round(landscapemax) }, { "name": "主厅", "max": 0.20 if ifratio else round(mainmax) }, { "name": "其他建筑", "max": 0.20 if ifratio else round(othermax) }, ] c = ( Radar().set_colors(color).add_schema( schema=c_schema, shape="circle", # 图片中心位置 center=["50%", "50%"], # 雷达图半径大小 radius="80%", angleaxis_opts=opts.AngleAxisOpts( # 径向轴大小 # min_=0, # max_=360, # is_clockwise=False, # 径向轴间隔大小 interval=4, axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=False), ), textstyle_opts=opts.TextStyleOpts(font_size=20), radiusaxis_opts=opts.RadiusAxisOpts( min_=0, max_=1000, interval=200, splitarea_opts=opts.SplitAreaOpts( is_show=False, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), polar_opts=opts.PolarOpts(), splitarea_opt=opts.SplitAreaOpts(is_show=False), splitline_opt=opts.SplitLineOpts(is_show=False), ).add( series_name=name, data=data, # 透明度 areastyle_opts=opts.AreaStyleOpts(opacity=0.2), # 线宽 linestyle_opts=opts.LineStyleOpts(width=2), label_opts=opts.LabelOpts(font_size=20)).set_global_opts( title_opts=opts.TitleOpts( title=name, pos_left="22%", pos_top="10", ), legend_opts=opts.LegendOpts(pos_right=10))) return c
from pyecharts import options as opts from pyecharts.charts import Polar from pyecharts.faker import Faker c = ( Polar() .add_schema( radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week, type_="category"), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=10), ) .add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar") .set_global_opts(title_opts=opts.TitleOpts(title="Polar-RadiusAxis")) .set_series_opts(label_opts=opts.LabelOpts(is_show=True)) .render("Polar_radius.html") )
import datetime import math import pyecharts.options as opts import random from pyecharts.charts import * from pyecharts.components import Table from pyecharts.faker import POPULATION from pyecharts.globals import CurrentConfig CurrentConfig.ONLINE_HOST = "https://cdn.kesci.com/lib/pyecharts_assets/" # %% # 直角坐标系图表 # 直方图 x_data = ['apple', 'huawei', 'xiaomi', 'oppo', 'vivo', 'meizu'] y_data = [123, 312, 89, 107, 82, 23] bar = (Bar().add_xaxis(x_data).add_yaxis('', y_data)) bar.render() # %% # 折线图 x_data = ['apple', 'huawei', 'xiaomi', 'oppo', 'vivo', 'meizu'] y_data = [123, 312, 89, 107, 82, 23] bar = (Line().add_xaxis(x_data).add_yaxis('', y_data)) bar.render() # %% # 折线图 x_data = ['apple', 'huawei', 'xiaomi', 'oppo', 'vivo', 'meizu'] y_data = [[random.randint(100, 200) for i in range(10)] for item in x_data] Box = Boxplot() Box.add_xaxis(x_data) Box.add_yaxis('', Box.prepare_data(y_data)) bar.render()
is_clockwise=True, interval=90, max_=360 ), "category": lambda x: opts.AngleAxisOpts( data=x, type_="category", boundary_gap=True, start_angle=0, is_clockwise=True ) } RADIUSAX = { "value": opts.RadiusAxisOpts( type_="value", boundary_gap=True, max_=100 ), "category": lambda x: opts.RadiusAxisOpts( data=x, type_="category", boundary_gap=True ) } SINGLEAX = { "time": opts.SingleAxisOpts( pos_right=10, pos_top=50, pos_bottom=50, type_="time" )
def radar_angle_radius_axis_opts() -> Radar: data = [ { "value": [4, -4, 2, 3, 0, 1], "name": "预算分配" }, ] c_schema = [ { "name": "销售", "max": 4, "min": -4 }, { "name": "管理", "max": 4, "min": -4 }, { "name": "技术", "max": 4, "min": -4 }, { "name": "客服", "max": 4, "min": -4 }, { "name": "研发", "max": 4, "min": -4 }, { "name": "市场", "max": 4, "min": -4 }, ] c = (Radar().set_colors(["#4587E7"]).add_schema( schema=c_schema, shape="circle", center=["50%", "50%"], radius="80%", angleaxis_opts=opts.AngleAxisOpts( min_=0, max_=360, is_clockwise=False, interval=5, axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=False), ), radiusaxis_opts=opts.RadiusAxisOpts( min_=-4, max_=4, interval=2, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1), )), polar_opts=opts.PolarOpts(), splitarea_opt=opts.SplitAreaOpts(is_show=False), splitline_opt=opts.SplitLineOpts(is_show=False), ).add( series_name="预算", data=data, areastyle_opts=opts.AreaStyleOpts(opacity=0.1), linestyle_opts=opts.LineStyleOpts(width=1), )) return c
""" Gallery 使用 pyecharts 1.1.0 参考地址: https://www.echartsjs.com/examples/editor.html?c=line-polar2 目前无法实现的功能: 1、赞无 """ data = [] for i in range(0, 360 + 1): t = i / 180 * math.pi r = math.sin(2 * t) * math.cos(2 * t) data.append([r, i]) (Polar(init_opts=opts.InitOpts(width="1600px", height="800px")).add( series_name="line", data=data, label_opts=opts.LabelOpts(is_show=False), symbol_size=0, ).add_schema( angleaxis_opts=opts.AngleAxisOpts(start_angle=0, type_="value", is_clockwise=True), radiusaxis_opts=opts.RadiusAxisOpts(min_=0), ).set_global_opts( tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), title_opts=opts.TitleOpts(title="极坐标双数值轴"), ).render("two_value_axes_in_polar_2.html"))
c = (Radar().set_colors(["#4587E7"]).add_schema( schema=c_schema, shape="circle", center=["50%", "50%"], radius="80%", angleaxis_opts=opts.AngleAxisOpts( min_=0, max_=360, is_clockwise=False, interval=5, axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=False), ), radiusaxis_opts=opts.RadiusAxisOpts( min_=-4, max_=4, interval=2, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), polar_opts=opts.PolarOpts(), splitarea_opt=opts.SplitAreaOpts(is_show=False), splitline_opt=opts.SplitLineOpts(is_show=False), ).add( series_name="预算", data=data, areastyle_opts=opts.AreaStyleOpts(opacity=0.1), linestyle_opts=opts.LineStyleOpts(width=1), ).render("Radar_angle_radius_axis.html"))
polar.add("", data) # 调整角度坐标轴样式 polar.add_schema( angleaxis_opts=opts.AngleAxisOpts( interval=90, max_=360 ) ) polar.render_notebook() # %% [markdown] # #### 极坐标柱状图 polar = Polar() polar.add("", list(zip(Faker.choose(), Faker.values())), type_="bar") polar.add_schema( radiusaxis_opts=opts.RadiusAxisOpts(type_="category"), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True) ) polar.render_notebook() # %% [markdown] # #### 极坐标玫瑰图 polar = Polar() polar.add("A", list(zip(Faker.values(), Faker.animal)), type_="bar", stack="g1") .add("B", list(zip(Faker.values(), Faker.animal)), type_="bar", stack="g1") .add("C", list(zip(Faker.values(), Faker.animal)), type_="bar", stack="g1") # 添加分类型角度坐标轴 polar.add_schema(angleaxis_opts=opts.AngleAxisOpts(type_="category")) polar.render_notebook()
def polarChart(df): type_of_plot = st.selectbox("Select Type of Plot",["POLAR1","POLAR2","POLAR3 Angle"]) all_columns = df.columns #st.success("Generating Customizable Plot of {} for {}".format(type_of_plot)) if type_of_plot == 'POLAR1': columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' ) columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' ) # columns_to_plot2 = st.selectbox("Select 1 column",all_columns, key='c' ) n = df[[columns_to_plot, columns_to_plot1]].sort_values(by = columns_to_plot1 , ascending = True) cje = n[columns_to_plot].tolist() other_var = n[columns_to_plot1].tolist() # cje = df[columns_to_plot].tolist() # other_var = df[columns_to_plot1].sort_values(ascending = True).tolist() # other_var1 = df[columns_to_plot2].tolist() polar = Polar() polar.add_schema( radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_="category", splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), axistick_opts=opts.AxisTickOpts(is_show=False)), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axistick_opts=opts.AxisTickOpts(is_show=False))) polar.add(columns_to_plot1, other_var, type_="bar") polar.set_global_opts(toolbox_opts=opts.ToolboxOpts()) polar.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=8, font_weight='bold')) return polar if type_of_plot == 'POLAR2': columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' ) columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' ) columns_to_plot2 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot]], key='c' ) columns_to_plot3 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot]], key='c' ) columns_to_plot4 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot, columns_to_plot3]], key='c' ) n = df[[columns_to_plot, columns_to_plot1, columns_to_plot2, columns_to_plot3, columns_to_plot4]].sort_values(by = columns_to_plot1 , ascending = True) cje = n[columns_to_plot].tolist() other_var = n[columns_to_plot1].tolist() other_var2 = n[columns_to_plot2].tolist() other_var3 = n[columns_to_plot3].tolist() other_var4 = n[columns_to_plot4].tolist() polar = Polar() polar.add_schema( radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_= "category", splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), axistick_opts=opts.AxisTickOpts(is_show=False)), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axistick_opts=opts.AxisTickOpts(is_show=False))) polar.add(columns_to_plot1, other_var, type_="bar" ) polar.add(columns_to_plot2, other_var2, type_="bar") polar.add(columns_to_plot3, other_var3, type_="bar") polar.add(columns_to_plot4, other_var4, type_="bar") polar.set_global_opts(toolbox_opts=opts.ToolboxOpts(),) polar.set_series_opts(label_opts=opts.LabelOpts(is_show=True)) return polar if type_of_plot == 'POLAR3 Angle': columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' ) columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' ) columns_to_plot2 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot]], key='c' ) columns_to_plot3 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot]], key='c' ) columns_to_plot4 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot, columns_to_plot3]], key='c' ) n = df[[columns_to_plot, columns_to_plot1, columns_to_plot2, columns_to_plot3, columns_to_plot4]].sort_values(by = columns_to_plot1 , ascending = True) cje = n[columns_to_plot].tolist() other_var = n[columns_to_plot1].tolist() other_var2 = n[columns_to_plot2].tolist() other_var3 = n[columns_to_plot3].tolist() other_var4 = n[columns_to_plot4].tolist() polar = Polar() polar.add_schema( # radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_= "category", # splitline_opts=opts.SplitLineOpts(is_show=False), # axisline_opts=opts.AxisLineOpts(is_show=False), # axistick_opts=opts.AxisTickOpts(is_show=False)), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True,type_= "category", splitline_opts=opts.SplitLineOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axistick_opts=opts.AxisTickOpts(is_show=False))) polar.add(columns_to_plot1, other_var, type_="bar", stack="stack0" ) polar.add(columns_to_plot2, other_var2, type_="bar" , stack="stack0") polar.add(columns_to_plot3, other_var3, type_="bar" , stack="stack0") polar.add(columns_to_plot4, other_var4, type_="bar" , stack="stack0") polar.set_global_opts(toolbox_opts=opts.ToolboxOpts()) polar.set_series_opts(label_opts=opts.LabelOpts(is_show=False)) return polar
( r.add_schema( schema=myschema, shape="circle", #图片形状 center=["50%", "50%"], #图片中心位置 radius="80%", #图片半径大小 angleaxis_opts=opts.AngleAxisOpts( axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=False), ), radiusaxis_opts=opts.RadiusAxisOpts( min_=0, max_=7, interval=1, splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1) ), splitline_opts=opts.series_options.SplitLineOpts(is_show=True, linestyle_opts={'color':'grey','opacity':0.8}) ), polar_opts=opts.PolarOpts(), splitline_opt=opts.SplitLineOpts(is_show=False), textstyle_opts=opts.TextStyleOpts(color="black"), ) .add( series_name="美国队长", data=captain_america, areastyle_opts=opts.AreaStyleOpts(opacity=0.1), linestyle_opts=opts.LineStyleOpts(width=1), ) .add(
def show_pyecharts(): x_data = [ '0.0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9', '1.0' ] y_data = [ '1533', '573', '502', '491', '520', '556', '577', '788', '1252', '20564', '6393' ] #情感分析柱状图 bar = (Bar().add_xaxis(x_data).add_yaxis( "情感分析", y_data, label_opts=opts.LabelOpts(is_show=False), color='#3498DB').set_global_opts(title_opts={ "text": "台海舆论情感分析", "subtext": "大于0.5为正面评价,小于0.5为负面评价" })) #台湾网饼图 x_data2 = [ "文化", "经贸", "媒体专栏", "网友专栏", "两岸专家", "两岸", "台商", "部委", "台海时事", "网友快言", "海峡时评", "两岸快评" ] y_data2 = [553, 553, 35, 39, 448, 465, 553, 321, 553, 406, 553, 556] pie = (Pie(init_opts=opts.InitOpts(theme=ThemeType.CHALK)).add( series_name="中国台湾网", data_pair=[list(z) for z in zip(x_data2, y_data2)], radius=["50%", "70%"], label_opts=opts.LabelOpts(is_show=False, position="center"), ).set_colors([ "#E8F8F5", "#D1F2EB", "#A3E4D7", "#76D7C4", "#48C9B0", "#1ABC9C", "#17A589", "#148F77", "#117864", "#0E6251F", "#73C6B6", "#45B39D" ]).set_global_opts(legend_opts=opts.LegendOpts( pos_left="legft", orient="vertical")).set_series_opts( tooltip_opts=opts.TooltipOpts( trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"), )) #词云图 word = (WordCloud().add( "", list1, word_size_range=[20, 100], shape=SymbolType.DIAMOND, textstyle_opts=opts.TextStyleOpts(font_family="cursive"), )) #折线图1 y2[0], y2[1], y2[2] = None, None, None y4[1] = None line = (Line().add_xaxis(xaxis_data=x1).add_yaxis( series_name="微博", symbol="emptyCircle", is_symbol_show=True, color="#F2D7D5", y_axis=y1, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis( series_name="环球网", symbol="emptyCircle", is_symbol_show=True, color="#C0392B", y_axis=y2, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis( series_name="中国台湾网", symbol="emptyCircle", is_symbol_show=True, color="#641E16", y_axis=y3, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis( series_name="知乎", symbol="emptyCircle", is_symbol_show=True, color="#9B59B6", y_axis=y4, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis( series_name="中国日报网", symbol="emptyCircle", is_symbol_show=True, color="#512E5F", y_axis=y5, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis( series_name="中新网", symbol="emptyCircle", is_symbol_show=True, color="#2980B9", y_axis=y6, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)). add_yaxis( series_name="今日头条", symbol="emptyCircle", is_symbol_show=True, color="#154360", y_axis=y7, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis( series_name="光明网", symbol="emptyCircle", is_symbol_show=True, color="#3498DB", y_axis=y8, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis( series_name="凤凰网", symbol="emptyCircle", is_symbol_show=True, color="#1ABC9C", y_axis=y9, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis( series_name="新华网", symbol="emptyCircle", is_symbol_show=True, color="#0E6251", y_axis=y10, label_opts=opts.LabelOpts(is_show=False), linestyle_opts=opts.LineStyleOpts( width=3)).set_global_opts( tooltip_opts=opts.TooltipOpts( trigger="axis"), yaxis_opts=opts.AxisOpts( type_="value", axistick_opts=opts.AxisTickOpts( is_show=True), splitline_opts=opts.SplitLineOpts( is_show=True), ), xaxis_opts=opts.AxisOpts( type_="category", boundary_gap=False, axisline_opts=opts.AxisLineOpts( is_on_zero=False, linestyle_opts=opts.LineStyleOpts( color="#d14a61"))), )) #平台占比饼图 x_data3 = [ "微博", "知乎", "中国台湾网", "环球网", "日报网", "中新网", "今日头条", "光明网", "凤凰网", "新华网" ] y_data3 = [5401, 157, 5035, 3245, 4296, 5574, 1891, 3131, 1052, 1997] data_pair = [list(z) for z in zip(x_data3, y_data3)] data_pair.sort(key=lambda x: x[1]) pie2 = (Pie(init_opts=opts.InitOpts(theme=ThemeType.ROMA)).add( series_name="访问来源", data_pair=data_pair, rosetype="radius", radius="55%", center=["50%", "50%"], label_opts=opts.LabelOpts(is_show=False, position="center"), ).set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{d}%"))) #折线图2 line2 = (Line().add_xaxis(xaxis_data=x_data4).add_yaxis( series_name="热度走势", y_axis=y_data4, color="#FF69B4", markpoint_opts=opts.MarkPointOpts( data=[opts.MarkPointItem(type_="max")]), symbol="emptyCircle", is_symbol_show=True, is_smooth=True, label_opts=opts.LabelOpts(is_show=True), ).set_global_opts( tooltip_opts=opts.TooltipOpts(is_show=False), yaxis_opts=opts.AxisOpts( type_="value", axistick_opts=opts.AxisTickOpts(is_show=True), splitline_opts=opts.SplitLineOpts(is_show=True), ), xaxis_opts=opts.AxisOpts(type_="category", boundary_gap=False, axislabel_opts=opts.LabelOpts(rotate=45)), )) #条形图 line3 = (Bar().add_xaxis(x_data5).add_yaxis( "平均值", y_data5, label_opts=opts.LabelOpts(is_show=False), color='#6A5ACD').reversal_axis().extend_axis(yaxis=opts.AxisOpts( type_='value', name='转发次数', position='left', )).set_global_opts( title_opts={"text": "评论与转发关系图"}, xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts( formatter='{value}(评论数量)')), )) #圆 radius = (Polar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)).add_schema( radiusaxis_opts=opts.RadiusAxisOpts(data=x_data6, type_="category"), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=100000), ).add("点赞数量", y_data6, type_="bar").set_global_opts( title_opts=opts.TitleOpts(title="")).set_series_opts( label_opts=opts.LabelOpts(is_show=True))) return render_template("index2.html", bar_data=bar.dump_options(), word_data=word.dump_options(), pie_data=pie.dump_options(), pie2_data=pie2.dump_options(), line_data=line.dump_options(), line2_data=line2.dump_options(), line3_data=line3.dump_options(), radius_data=radius.dump_options())
def pyecharts(): from pyecharts.charts import Bar from pyecharts.faker import Faker from pyecharts import options as opts from pyecharts.charts import Polar from pyecharts.charts import HeatMap from pyecharts.charts import Tree r1 = ['草莓', '芒果', '葡萄', '雪梨', '西瓜', '柠檬', '车厘子'] r2 = [127, 33, 110, 29, 146, 121, 36] r3 = [25, 87, 114, 131, 130, 94, 146] c1 = (Bar({ "width": "100%" }).add_xaxis(r1).add_yaxis("商家A", r2).add_yaxis("商家B", r3).set_global_opts( title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题"))) c2 = (Polar({ "width": "100%" }).add_schema( radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week, type_="category"), angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=10), ).add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar").set_global_opts( title_opts=opts.TitleOpts(title="Polar-RadiusAxis")).set_series_opts( label_opts=opts.LabelOpts(is_show=True))) data = [{ "children": [ { "name": "B" }, { "children": [{ "children": [{ "name": "I" }], "name": "E" }, { "name": "F" }], "name": "C", }, { "children": [ { "children": [{ "name": "J" }, { "name": "K" }], "name": "G" }, { "name": "H" }, ], "name": "D", }, ], "name": "A", }] c3 = (Tree({ "width": "100%" }).add("", data).set_global_opts(title_opts=opts.TitleOpts(title="Tree-基本示例"))) value = [[i, j, int(i * j * 3.14 * 314 % 50)] for i in range(24) for j in range(7)] c4 = (HeatMap({ "width": "100%" }).add_xaxis(Faker.clock).add_yaxis( "series0", Faker.week, value, label_opts=opts.LabelOpts(is_show=True, position="inside"), ).set_global_opts( title_opts=opts.TitleOpts(title="HeatMap-Label 显示"), visualmap_opts=opts.VisualMapOpts(), )) put_grid([[put_html(c1.render_notebook()), put_html(c2.render_notebook())], [put_html(c3.render_notebook()), put_html(c4.render_notebook())]], cell_width='1fr', cell_height='1fr')
def view_radar(self, df_view): """ 画雷达图 例子: page_ = Page() for v in view_lst: view_label[1] = v df_view = get_view_dt(df_all, 'label', view_label, call_cols, call_dct) c = view_radar(df_view) page_.add(c) print(f'Finished {v}') print('Finished all') page_.render_notebook() """ c_schema = [] try: add_name1, add_name2 = df_view.columns[1], df_view.columns[2] add_value1, add_value2 = [ df_view.iloc[list(range(12)), 1].tolist() ], [df_view.iloc[list(range(12)), 2].tolist()] max_v = max(max(add_value1[0]), max(add_value2[0])) min_v = min(min(add_value1[0]), min(add_value2[0])) max_v_set = 1 if max_v > 0.65 else max_v + min_v for i in df_view.loc[list(range(12)), 'index']: c_schema.append({"name": i, "max": max_v_set, "min": 0}) except: add_name1, add_name2 = df_view.columns[1], df_view.columns[2] add_value1, add_value2 = [df_view.iloc[:, 1].tolist() ], [df_view.iloc[:, 2].tolist()] max_v = max(max(add_value1[0]), max(add_value2[0])) min_v = min(min(add_value1[0]), min(add_value2[0])) max_v_set = 1 if max_v > 0.65 else max_v + min_v for i in df_view.loc[:, 'index']: c_schema.append({"name": i, "max": max_v_set, "min": 0}) c = (Radar().add_schema( c_schema, shape="circle", center=["50%", "50%"], radius="80%", angleaxis_opts=opts.AngleAxisOpts( min_=0, max_=360, is_clockwise=False, interval=5, axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False), axisline_opts=opts.AxisLineOpts(is_show=False), splitline_opts=opts.SplitLineOpts(is_show=False), ), radiusaxis_opts=opts.RadiusAxisOpts( min_=0, max_=round(max_v_set, 3), interval=round(max_v_set / 5, 3), splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)), ), polar_opts=opts.PolarOpts(), splitarea_opt=opts.SplitAreaOpts(is_show=False), splitline_opt=opts.SplitLineOpts(is_show=False), ).add(add_name1, add_value1, color="#f9713c").add( add_name2, add_value2, color="#b3e4a1", areastyle_opts=opts.AreaStyleOpts(opacity=0.3)).set_series_opts( label_opts=opts.LabelOpts(is_show=False))) return c
score_2018.append(int(school_data[school_data['year'] == 2018]['score'])) score_2017.append(int(school_data[school_data['year'] == 2017]['score'])) rank_2019.append(int(school_data[school_data['year'] == 2019]['ranking'])) rank_2018.append(int(school_data[school_data['year'] == 2018]['ranking'])) rank_2017.append(int(school_data[school_data['year'] == 2017]['ranking'])) print(ranking) bar2 = (Bar().add_xaxis(top_school).add_yaxis( "2017年", score_2017, category_gap="20%").add_yaxis( "2018年", score_2018, category_gap="20%").add_yaxis( "2019年", score_2019, category_gap="20%").set_global_opts( title_opts=opts.TitleOpts(title="计算机强校的三年分数变化情况"), xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts( rotate=-30, font_weight='bold')))) bar2.render('计算机强校的三年分数变化情况.html') polar = (Polar().add_schema(radiusaxis_opts=opts.RadiusAxisOpts( data=[2019, 2018, 2017], type_="category")).add( "清华大学", ranking[0], type_="bar", stack="stack0").add( "浙江大学", ranking[1], type_="bar", stack="stack0").add("北京大学", ranking[2], type_="bar", stack="stack0").add( "华中科技大学", ranking[3], type_="bar", stack="stack0").add( "国防科技大学", ranking[4], type_="bar", stack="stack0").add( "上海交通大学",
def draw_radar(season_x, season_name, filechart, seasonareacolor, seasonlinecolor): # 建立schema的json文件 season_x.columns = [season_name] season_index = season_x.index.to_list() # print(season_index) # n_max, n_min = max(season_x), min(season_x) n_max = max(enumerate(season_x[0]), key=operator.itemgetter(1))[1] n_min = min(enumerate(season_x[0]), key=operator.itemgetter(1))[1] # 用于获取对象的哪些维的数据 # print(n_max, n_min) df_season = pd.DataFrame({'name': season_index}) df_season['max'], df_season['min'] = n_max, n_min # season_js = df_season.to_json(orient='records') # print(season_js) # 设置16方位, 逆时针排序 season_js = [ {"name": "N", "max": n_max, "min": n_min}, {"name": "NNW", "max": n_max, "min": n_min}, {"name": "NW", "max": n_max, "min": n_min}, {"name": "WNW", "max": n_max, "min": n_min}, {"name": "W", "max": n_max, "min": n_min}, {"name": "WSW", "max": n_max, "min": n_min}, {"name": "SW", "max": n_max, "min": n_min}, {"name": "SSW", "max": n_max, "min": n_min}, {"name": "S", "max": n_max, "min": n_min}, {"name": "SSE", "max": n_max, "min": n_min}, {"name": "SE", "max": n_max, "min": n_min}, {"name": "ESE", "max": n_max, "min": n_min}, {"name": "E", "max": n_max, "min": n_min}, {"name": "ENE", "max": n_max, "min": n_min}, {"name": "NE", "max": n_max, "min": n_min}, {"name": "NNE", "max": n_max, "min": n_min}, ] # 设置数据 fengsus = season_x[0].to_list() data_fengsu = [{'value': fengsus, 'name': '风频数'}] # print(data_fengsu) charts = Radar() charts.set_colors(['#4587E7']) # 设置颜色 charts.add_schema(schema=season_js, shape='circle', center=['50%', '50%'], radius='80%', angleaxis_opts=opts.AngleAxisOpts( min_=0, # 坐标轴刻度最小值 max_=360, # 坐标轴刻度最大值 is_clockwise=True, interval=22.5, # 强制设置坐标轴分割间隔 axistick_opts=opts.AxisTickOpts(is_show=False), axislabel_opts=opts.LabelOpts(is_show=False,), # 坐标轴线标签配置项 axisline_opts=opts.AxisLineOpts(is_show=True), # 坐标轴线风格配置项 splitline_opts=opts.SplitLineOpts(is_show=True) # 分割线配置项 ), radiusaxis_opts=opts.RadiusAxisOpts( min_=n_min, # 坐标轴刻度最小值 max_=n_max, # 坐标轴刻度最大值 interval=2, # 强制设置坐标轴分割间隔 splitarea_opts=opts.SplitAreaOpts( is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=0.2, ) ), splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(is_show=True, width=0.5, color='grey')), axislabel_opts=opts.LabelOpts(is_show=True, font_size=12, color='grey'), # 坐标轴线标签配置项 ), polar_opts=opts.PolarOpts(), splitarea_opt=opts.SplitAreaOpts(is_show=True), splitline_opt=opts.SplitLineOpts(is_show=False), # 分割线配置项 textstyle_opts=opts.TextStyleOpts(color='black', font_size=14) ) charts.add(series_name='%s玫瑰图' % season_name, # 系列名称 data=data_fengsu, # 系列数据 areastyle_opts=opts.AreaStyleOpts(opacity=0.5, # 系列面样式设置 color=seasonareacolor), linestyle_opts=opts.LineStyleOpts(width=2, # 系列线样式设置 color=seasonlinecolor), label_opts=opts.LabelOpts(is_show=False), ) # 系列标签设置 charts.render(filechart)