def image_host_apps(doc_path, host_apps, host):
    if host_apps.get(host['id']) is None:
        return

    data_inner = []
    data_outer = []

    for i in host_apps.get(host['id']):
        number = 0
        for x in i.get('apps'):
            number = number + x.get('number')
            data_outer.append([x.get('name'), x.get('number')])

        data_inner.append(["★%s" % (i.get('user')), number])

    options = opts.InitOpts(js_host=os.path.join(os.getcwd(), "scripts/javascript/"),
                            animation_opts=opts.AnimationOpts(animation=False))
    pipe = (
        Pie(options)
            .add('', data_inner, radius=["0%", "30%"],
                 label_opts=opts.LabelOpts(formatter='{b}'))
            .add('', data_outer, radius=['55%', '80%'],
                 label_opts=opts.LabelOpts(formatter='{b}:{c} ({d}%)', font_size=13))
            .set_global_opts(legend_opts=opts.LegendOpts(orient='vertical', pos_left=0),
                             title_opts=opts.TitleOpts(title="应用分布", pos_left='center'))
    )
    make_snapshot(snapshot, pipe.render(os.path.join(doc_path, "render_%s.html" % (host['ip'].replace(".", "_")))),
                  os.path.join(doc_path, "host_app_%s.png" % (host['ip'].replace(".", "_"))), pixel_ratio=1, delay=1,
                  is_remove_html=True)
Exemplo n.º 2
0
def grid(factor, factor2, instrument):
    gridchart = Grid(init_opts=opts.InitOpts(width="100vw",
                                             height="50vh",
                                             animation_opts=opts.AnimationOpts(
                                                 animation=True)))
    gridchart.add(  #左边画最新数据
        getplot(factor,
                factor2,
                kdata_part,
                nnv,
                new_p,
                instrument,
                xaxis_index=[0, 1]),
        grid_opts=opts.GridOpts(pos_left="5%", pos_right="68%"))
    gridchart.add(  # 右边画全样本数据
        getplot(factor,
                factor2,
                kdata_all,
                nv,
                new_a,
                instrument,
                xaxis_index=None),
        grid_opts=opts.GridOpts(pos_left="40%", pos_right="5%"))

    return gridchart
Exemplo n.º 3
0
def bar_base_with_animation() -> Bar:
    c = (Bar(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(
        animation_delay=1000, animation_easing="elasticOut"))).add_xaxis(
            x).add_yaxis("北京", beijing).add_yaxis(
                "新疆", xingjiang).set_global_opts(title_opts=opts.TitleOpts(
                    title="北京与新疆教育经费支出对比", subtitle="缺2012年及2018年")))
    return c
Exemplo n.º 4
0
def bars(name, dict_values):

    # 链式调用
    c = (
        Bar(init_opts=opts.InitOpts(  # 初始配置项
            theme=ThemeType.MACARONS,
            animation_opts=opts.AnimationOpts(
                animation_delay=1000,
                animation_easing="cubicOut"  # 初始动画延迟和缓动效果
            ))).add_xaxis(xaxis_data=name)  # x轴
        .add_yaxis(series_name="股票型", yaxis_data=dict_values['股票型'])  # y轴
        .add_yaxis(series_name="混合型", yaxis_data=dict_values['混合型'])  # y轴
        .add_yaxis(series_name="债券型", yaxis_data=dict_values['债券型'])  # y轴
        .add_yaxis(series_name="指数型", yaxis_data=dict_values['指数型'])  # y轴
        .add_yaxis(series_name="QDII型", yaxis_data=dict_values['QDII型'])  # y轴
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title='涨跌幅',
                subtitle='李运辰绘制',  # 标题配置和调整位置
                title_textstyle_opts=opts.TextStyleOpts(
                    font_family='SimHei',
                    font_size=25,
                    font_weight='bold',
                    color='red',
                ),
                pos_left="90%",
                pos_top="10",
            ),
            xaxis_opts=opts.AxisOpts(name='阶段',
                                     axislabel_opts=opts.LabelOpts(rotate=45)),
            # 设置x名称和Label rotate解决标签名字过长使用
            yaxis_opts=opts.AxisOpts(name='涨跌点'),
        ).render("基金各个阶段涨跌幅.html"))
    def draw_bar3D(cls, title: str, data: pd.DataFrame) -> Bar3D:
        """
        根据df内容绘制3D柱状图
        :param title:           标题
        :param data:            包含三轴数据的dataframe  index为x轴 column为Y轴 value为z轴
        :return:
        """
        data_list = []
        index_list = data.index.tolist()
        column_list = data.columns.tolist()

        # 获取dataframe最大最小值
        min_data = data.min().min()
        max_data = data.max().max()
        # 遍历dataframe,准备待操作数组
        for i in range(len(index_list)):
            for j in range(len(column_list)):
                # 记录 XYZ
                temp_list = [index_list[i], column_list[j], data.iloc[i, j]]
                # print(i,j,index_list[i],column_list[j])
                data_list.append(temp_list)

        c = (
            Bar3D(init_opts=opts.InitOpts(
                width=DEFAULT_WIDTH,
                animation_opts=opts.AnimationOpts(
                    animation_delay=200,
                    animation_easing="bounceOut"),  #   增加启动动效
            )).add(
                series_name=title,
                data=data_list,
                xaxis3d_opts=opts.Axis3DOpts(type_="category",
                                             data=index_list),
                yaxis3d_opts=opts.Axis3DOpts(type_="category",
                                             data=column_list),
                zaxis3d_opts=opts.Axis3DOpts(type_="value"),
            ).set_series_opts(label_opts=opts.LabelOpts(is_show=True)).
            set_global_opts(
                title_opts=opts.TitleOpts(title=title, pos_left="0%"),
                toolbox_opts=opts.ToolboxOpts(),  # 显示工具箱
                tooltip_opts=opts.TooltipOpts(is_show=True),
                axispointer_opts=opts.AxisPointerOpts(
                    is_show=True, type_="none"),  # 指针移动时显示所有数值
                legend_opts=opts.LegendOpts(
                    is_show=True,
                    selected_mode="multiple",
                    # pos_bottom="0%",
                    # pos_right="0%",
                    # orient="vertical",
                ),  # 显示图例说明
                # datazoom_opts=[
                #     opts.DataZoomOpts(
                #         range_start=0, range_end=100, orient="vertical", pos_left="2%"
                #     ),
                #     opts.DataZoomOpts(range_start=0, range_end=100, orient="horizontal"),
                # ],  # 增加缩放配置横纵轴都支持缩放
                visualmap_opts=opts.VisualMapOpts(max_=max_data, min_=min_data)
                # visualmap_opts=opts.VisualMapOpts(type_="color", max_=1, min_=-1),
            ))
        return c
Exemplo n.º 6
0
    def draw(self, symbol, fn_render):
        fn = get_dss() + 'fut/bar/day_' + symbol + '.csv'
        df1 = pd.read_csv(fn)
        # print(df1.head())
        price_min = int(df1.close.min() * 0.99)
        price_max = df1.close.max()

        kline = self.gen_kline(df1, symbol)
        line_cci = self.gen_cci(df1, 100)

        grid_chart = Grid(init_opts=opts.InitOpts(
            width="1390px",
            height="700px",
            animation_opts=opts.AnimationOpts(animation=False),
        ))
        grid_chart.add(
            kline,
            grid_opts=opts.GridOpts(pos_left="10%",
                                    pos_right="8%",
                                    height="60%"),
        )
        grid_chart.add(
            line_cci,
            grid_opts=opts.GridOpts(pos_left="10%",
                                    pos_right="8%",
                                    pos_top="75%",
                                    height="17%"),
        )

        grid_chart.render(fn_render)
Exemplo n.º 7
0
def grid_chart(dataframe) -> Grid:
    grid = (
        Grid(init_opts=opts.InitOpts(
            width="1200px",
            height="800px",
            #设置动画
            animation_opts=opts.AnimationOpts(animation_delay=1000,
                                              animation_easing="elasticOut"),
        )).add(
            line_datazoom_CO2(dataframe),  # 图表实例,仅 `Chart` 类或者其子类

            # grid 组件离容器右侧的距离。
            # right 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比。
            grid_opts=opts.GridOpts(pos_top="4%", height="24%")).
        add(
            line_datazoom_temp(dataframe),  # 图表实例,仅 `Chart` 类或者其子类

            # grid 组件离容器右侧的距离。
            # right 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比。
            grid_opts=opts.GridOpts(pos_bottom="39%", height="24%")
        ).add(
            bar_datazoom_rh(dataframe),  # 图表实例,仅 `Chart` 类或者其子类

            # grid 组件离容器右侧的距离。
            # right 的值可以是像 20 这样的具体像素值,可以是像 '20%' 这样相对于容器高宽的百分比。
            grid_opts=opts.GridOpts(pos_bottom="6%",
                                    height="24%")).dump_options_with_quotes())

    return grid
Exemplo n.º 8
0
def bars(name, dict_values):

    # 链式调用
    c = (
        Bar(init_opts=opts.InitOpts(  # 初始配置项
            theme=ThemeType.MACARONS,
            animation_opts=opts.AnimationOpts(
                animation_delay=1000,
                animation_easing="cubicOut"  # 初始动画延迟和缓动效果
            ))).add_xaxis(xaxis_data=name)  # x轴
        .add_yaxis(series_name="up主昵称", yaxis_data=dict_values)  # y轴
        .set_global_opts(
            title_opts=opts.TitleOpts(
                title='李运辰',
                subtitle='up视频数',  # 标题配置和调整位置
                title_textstyle_opts=opts.TextStyleOpts(
                    font_family='SimHei',
                    font_size=25,
                    font_weight='bold',
                    color='red',
                ),
                pos_left="90%",
                pos_top="10",
            ),
            xaxis_opts=opts.AxisOpts(name='up主昵称',
                                     axislabel_opts=opts.LabelOpts(rotate=45)),
            # 设置x名称和Label rotate解决标签名字过长使用
            yaxis_opts=opts.AxisOpts(name='大学生学习视频视频数'),
        ).render("up主大学生学习视频视频数.html"))
Exemplo n.º 9
0
def test_bar_base_with_animation(fake_writer):
    c = (Bar(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(
        animation_delay=1000))).add_xaxis(["A", "B", "C"]).add_yaxis(
            "series0", [1, 2, 4]).add_yaxis("series1", [2, 3, 6]))
    c.render()
    _, content = fake_writer.call_args[0]
    assert_in("animationDelay", content)
Exemplo n.º 10
0
def bolling_backtest_grid_chart(df):
    """完整布林线回测图,传入的 df 需要有 open high low close volume upper median lower signal equity_curve 即可绘制 """

    # 布林线的 OHLC 图
    kline_chart = bolling_kline_chart(df, 3)  # 这里要控制3个轴同时缩放
    # Volume
    volume_chart = volume_bar_chart(df)
    # 资金曲线
    equity_chart = equity_line_chart(df)
    # 组合起来
    grid_chart = Grid(init_opts=opts.InitOpts(
        width="1000px",
        height="800px",
        bg_color="#ffffff",
        animation_opts=opts.AnimationOpts(animation=False),
    ))
    grid_chart.add(
        kline_chart,
        grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", height="40%"),
    )
    grid_chart.add(
        volume_chart,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="55%",
                                height="10%"),
    )
    grid_chart.add(
        equity_chart,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="75%",
                                height="10%"),
    )
    return grid_chart
Exemplo n.º 11
0
def base_kline_grid_chart(df, signal_infos=[]):
    """ 最最最基础的 K 线图,传入的 df 只需要有 open high low close volume 即可绘制 """
    # OHLC
    kline_chart = ohlc_kline_chart(df, signal_infos=signal_infos)
    # Volume
    volume_chart = volume_bar_chart(df)
    # 把 ohlc 和 volume 图组合起来
    grid_chart = Grid(init_opts=opts.InitOpts(
        width="1000px",
        height="800px",
        bg_color="#ffffff",
        animation_opts=opts.AnimationOpts(animation=False),
    ))
    grid_chart.add(
        kline_chart,
        grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", height="55%"),
    )
    grid_chart.add(
        volume_chart,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="70%",
                                height="15%"),
    )
    return grid_chart
Exemplo n.º 12
0
def KlinePlotting(target_file):
    global trend_punishment
    res = pickle.load(open(target_file, 'rb'))
    c = (Line().add_xaxis([item[0] for item in res]).add_yaxis(
        "打分",
        [item[1] for item in res],
        linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="打分"),
        xaxis_opts=opts.AxisOpts(type_="category"),
        datazoom_opts=[
            opts.DataZoomOpts(
                type_="slider",
                xaxis_index=[0],
                range_start=80,
                range_end=100,
            )
        ],
        tooltip_opts=opts.TooltipOpts(
            trigger="axis",
            axis_pointer_type="cross",
            background_color="rgba(245, 245, 245, 0.8)",
            border_width=1,
            border_color="#ccc",
            textstyle_opts=opts.TextStyleOpts(color="#000"),
        ),
    ))

    gridChart = Grid(init_opts=opts.InitOpts(width="1000px",
                                             height="500px",
                                             animation_opts=opts.AnimationOpts(
                                                 animation=False)))
    gridChart.add(c, grid_opts=opts.GridOpts(pos_left="10%", pos_right="10%"))
    gridChart.render("score_modified_plot_new_0.002.html")
Exemplo n.º 13
0
def bar_datazoom_inside() -> Timeline:
    tl = Timeline()
    for i in range(2014, 2020):
        c = (
            Bar(
            init_opts=opts.InitOpts(
                    animation_opts=opts.AnimationOpts(
                        animation_delay=1000, animation_easing="elasticOut"
                    )
                )
            )
            .add_xaxis(list(zip(list(data总.set_index('类别').index))))
            .add_yaxis("显示",list(data总["{}".format(i)]))
            .set_global_opts(
                title_opts=opts.TitleOpts(title="纵横小说月票榜"),
                datazoom_opts=opts.DataZoomOpts(type_="inside"),
                visualmap_opts=opts.VisualMapOpts(type_="color", max_=250000, min_=200,pos_right='20',pos_top='middle'),
                toolbox_opts=opts.ToolboxOpts(),
            )
            .set_series_opts(
            label_opts=opts.LabelOpts(is_show=False),
            markpoint_opts=opts.MarkPointOpts(
                data=[
                    opts.MarkPointItem(type_="max", name="最大值"),
                    opts.MarkPointItem(type_="min", name="最小值"),
                ]
            ),
        )
    )
        tl.add(c, "{}年".format(i))
    return tl
Exemplo n.º 14
0
def bar_base_with_animation() -> Bar:
    c = (Bar(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(
        animation_delay=1000, animation_easing="elasticOut"))).add_xaxis(
            Faker.choose()).add_yaxis("商家A", Faker.values()).add_yaxis(
                "商家B",
                Faker.values()).set_global_opts(title_opts=opts.TitleOpts(
                    title="Bar-动画配置基本示例", subtitle="我是副标题")))
    return c
Exemplo n.º 15
0
def bar_base_with_animation(x_values, one) -> Bar:
    c = (Bar(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(
        animation_delay=1000, animation_easing="elasticOut"))).add_xaxis(
            x_values).add_yaxis("2019", one).set_global_opts(
                title_opts=opts.TitleOpts(title=""),
                datazoom_opts=opts.DataZoomOpts(),
            ))
    return c
Exemplo n.º 16
0
def render_filter_legend_py():
    with st.echo("below"):
        c = (Bar(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(
            animation_delay=1000, animation_easing="elasticOut"))).add_xaxis(
                Faker.choose()).add_yaxis("商家A", Faker.values()).add_yaxis(
                    "商家B",
                    Faker.values()).set_global_opts(title_opts=opts.TitleOpts(
                        title="Bar-动画配置基本示例", subtitle="我是副标题")))
        st_pyecharts(c)
Exemplo n.º 17
0
def gen_bar_plot(
    chart_data: typing.Dict[str, typing.List[typing.List[typing.Union[float,
                                                                      int]]]],
    index: int,
    column: str,
    label: str,
) -> typing.Tuple[Bar, int]:
    if column in chart_data.keys():
        bar = Bar(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(
            animation=False), ))
        xaxis_data = [label for i in range(len(chart_data[column]))]
        bar.add_xaxis(xaxis_data=xaxis_data)
        bar.add_yaxis(
            series_name="Value",
            y_axis=chart_data[column],
            xaxis_index=index,
            yaxis_index=index,
            label_opts=opts.LabelOpts(is_show=False),
        )
        bar.set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                is_scale=True,
                grid_index=1,
                boundary_gap=False,
                axisline_opts=opts.AxisLineOpts(is_on_zero=False),
                axistick_opts=opts.AxisTickOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
                axislabel_opts=opts.LabelOpts(is_show=False),
                split_number=20,
                min_="dataMin",
                max_="dataMax",
            ),
            yaxis_opts=opts.AxisOpts(
                name=label,
                name_textstyle_opts=opts.TextStyleOpts(
                    color="red",
                    font_style="normal",
                    font_weight="normal",
                    font_family="Arial",
                    font_size=12,
                ),
                grid_index=1,
                is_scale=True,
                split_number=2,
                name_gap=0,
                axislabel_opts=opts.LabelOpts(is_show=False),
                axisline_opts=opts.AxisLineOpts(is_show=False),
                axistick_opts=opts.AxisTickOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
            ),
            legend_opts=opts.LegendOpts(is_show=False),
        )
        return bar, index + 1
    else:
        return None, index
Exemplo n.º 18
0
def draw_charts():

    pz = 'CF'
    vtSymbol = 'CF'

    fn = get_dss() + 'backtest/fut/' + pz + '/day_' + vtSymbol + '.csv'
    df1 = pd.read_csv(fn)
    # df1 = df1[df1.date >= '2019-01-20']
    #df1['datetime'] = df1['date'] + ' ' + df1['time']
    df1['datetime'] = df1['date']
    price_min = int(df1.close.min() * 0.99)
    price_max = df1.close.max()

    #fn  = get_dss( )+ 'fut/engine/aberration_raw/signal_aberration_raw_duo_deal_CF.csv'
    #fn  = get_dss( )+ 'fut/engine/aberration_raw/signal_aberration_raw_kong_deal_CF.csv'

    fn = get_dss(
    ) + 'fut/engine/aberration_enhance/signal_aberration_enhance_duo_deal_CF.csv'
    #fn  = get_dss( )+ 'fut/engine/aberration_enhance/signal_aberration_enhance_kong_deal_CF.csv'

    df2 = pd.read_csv(fn)
    dt_list = df2['datetime'].tolist()
    dt_list = [dt[:10] for dt in dt_list]
    # print(dt_list)
    df2['datetime'] = dt_list

    line = gen_line(df1, vtSymbol, price_min, price_max)
    line_atr = gen_atr(df1, 10)
    line_boll = gen_boll(df1, 10, 2)
    line = line.overlap(line_boll)

    scatter_open = gen_poit_open(df2)
    scatter_close = gen_poit_close(df2)
    line = line.overlap(scatter_open)
    line = line.overlap(scatter_close)

    grid_chart = Grid(init_opts=opts.InitOpts(
        width="1300px",
        height="700px",
        animation_opts=opts.AnimationOpts(animation=False),
    ))
    grid_chart.add(
        line,
        grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", height="60%"),
    )
    grid_chart.add(
        line_atr,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="76%",
                                height="17%"),
    )

    fn = get_dss() + 'backtest/render/k_deal_aberration_' + vtSymbol + '.html'
    grid_chart.render(fn)
Exemplo n.º 19
0
 def grid_chart(self):
     """
     组合图
     """
     grid_chart = Grid(
         init_opts=opts.InitOpts(
             width="1000px",
             height="800px",
             animation_opts=opts.AnimationOpts(animation=False),
         )
     )
     return grid_chart
def bar_with_animation():
    bar = Bar(init_opts=opts.InitOpts(
        theme='light',
        width='1000px',
        height='600px',
        animation_opts=opts.AnimationOpts(
            animation_delay=1000,  # 动画延时
            animation_easing='bounceIn')))
    bar.add_xaxis(Faker.choose())
    bar.add_yaxis('A', Faker.values())
    bar.add_yaxis('B', Faker.values())
    return bar
Exemplo n.º 21
0
def bar_base_with_animation(title, x, y, y_label) -> Bar:
    c = (
        Bar(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(
            animation_delay=1000,
            animation_easing="elasticOut"))).add_xaxis(x).add_yaxis(
                y_label,
                y).reversal_axis().set_series_opts(label_opts=opts.LabelOpts(
                    position="right")).set_global_opts(
                        title_opts=opts.TitleOpts(title=title),
                        # datazoom_opts=opts.DataZoomOpts(),
                    ))
    return c
Exemplo n.º 22
0
def ice_ga_shrinkage_chart(df):
    """ice ga shrinkage"""

    os_ma = pyecharts_float_values_data(df, 'os_ma', 6)
    # 信号信息
    signal_infos = bolling_signals_data(df)

    # k 线
    ohlc_chart = ohlc_kline_chart(df,
                                  x_axis_count=3,
                                  signal_infos=signal_infos)
    # os_ma
    os_ma_line = Line().add_xaxis(
        xaxis_data=pyecharts_time_data(df)).add_yaxis(
            y_axis=os_ma,
            series_name='os_ma',
            is_symbol_show=False,
            label_opts=None,
            is_smooth=True,
        )
    # 资金曲线
    equity_chart = equity_line_chart(df)

    grid_chart = Grid(init_opts=opts.InitOpts(
        width="1000px",
        height="600px",
        bg_color="#ffffff",
        animation_opts=opts.AnimationOpts(animation=False),
    ))
    grid_chart.add(
        ohlc_chart,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="5%",
                                height="30%"),
    )
    grid_chart.add(
        os_ma_line,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="40%",
                                height="20%"),
    )
    grid_chart.add(
        equity_chart,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="70%",
                                height="18%"),
    )
    return grid_chart
Exemplo n.º 23
0
def bar_base_with_animation():
    obj_bar = Bar(
        init_opts=opts.InitOpts(
            animation_opts=opts.AnimationOpts(
                animation_delay=1000,
                animation_easing="elasticOut"
            )
        )
    )
    obj_bar.add_xaxis(Faker.choose())
    obj_bar.add_yaxis("A", Faker.values())
    obj_bar.add_yaxis("B", Faker.values())
    obj_bar.set_global_opts(title_opts = opts.TitleOpts(title = "Bar-动画配置基本示例", subtitle = "副标题"))
    return obj_bar
Exemplo n.º 24
0
def bar_border_radius():
    c = (
        Bar(init_opts=opts.InitOpts(
            animation_opts=opts.AnimationOpts(  # 柱状图显示效果动画控制代码
                animation_delay=500,
                animation_easing="cubicOut"),
            theme=ThemeType.MACARONS,  # 柱状图显示主题
            page_title="Bar Learn",  # 设置html页面标题
        ))
        # .reversal_axis()  # 翻转XY轴
        .add_xaxis(["草莓", "芒果", "葡萄", "雪梨", "西瓜", "柠檬", "车厘子"]).add_yaxis(
            "A",
            Faker.values(),
            category_gap="50%",  # 柱间距对应的控制代码
            markpoint_opts=opts.MarkPointOpts(),
            is_selected=True  # A系列柱子是否显示对应的控制代码
        ).set_global_opts(
            title_opts=opts.TitleOpts(  # 标题
                title="Bar-参数使用例子", subtitle="副标题"),
            toolbox_opts=opts.ToolboxOpts(),  # toolbox 工具箱配置
            yaxis_opts=opts.AxisOpts(position="right", name="Y轴"),  # Y轴右侧控制
            datazoom_opts=opts.DataZoomOpts(),  # 数据区域放大缩小设置
        ).set_series_opts(
            itemstyle_opts={  # A系列柱子颜色渐变对应的控制代码
                "normal": {
                    "color":
                    JsCode("""
                        new echarts.graphic.LinearGradient(
                        0, 0, 0, 1, [{
                        offset: 0,
                        color: 'rgba(0, 244, 255, 1)'}, {
                        offset: 1,
                        color: 'rgba(0, 77, 167, 1)'}], false)"""),
                    "barBorderRadius": [6, 6, 6, 6],
                    "shadowColor":
                    'rgb(0, 160, 221)',
                }
            },
            # A系列柱子最大和最小值标记点对应的控制代码
            markpoint_opts=opts.MarkPointOpts(data=[
                opts.MarkPointItem(type_="max", name="最大值"),
                opts.MarkPointItem(type_="min", name="最小值"),
            ]),
            # A系列柱子最大和最小值标记线对应的控制代码
            markline_opts=opts.MarkLineOpts(data=[
                opts.MarkLineItem(type_="min", name="最小值"),
                opts.MarkLineItem(type_="max", name="最大值")
            ])))

    return c
Exemplo n.º 25
0
def country_base() -> Bar:
    results0 = countries.find()
    dis0 = []
    for result in results0:
        dis0.append(result['distance'])
    c = (
        Bar(init_opts=opts.InitOpts(
            animation_opts=opts.AnimationOpts(
                animation_delay=500,
                animation_easing="elasticOut",  # 延时动画效果
                animation_duration_update=1000), )).add_xaxis(
                    ["中国", "美国"]).add_yaxis("评分差距", dis0).set_global_opts(
                        title_opts=opts.TitleOpts(title="国家")))
    return c
Exemplo n.º 26
0
def draw_charts():

    vtSymbol = 'CF005'

    fn = get_dss() + 'fut/bar/min5_' + vtSymbol + '.csv'
    df1 = pd.read_csv(fn)
    df1 = df1[df1.date >= '2019-11-20']
    df1['datetime'] = df1['date'] + ' ' + df1['time']
    # print(df1.head())

    fn = get_dss() + 'fut/engine/rsiboll/signal_rsiboll_duo_deal_CF.csv'
    df2 = pd.read_csv(fn)

    kline = gen_kline(df1)
    line_rsi = gen_rsi(df1)
    line_atr = gen_atr(df1)
    scatter_deal_one = gen_poit_one(df2)
    scatter_deal_two = gen_poit_two(df2)
    scatter_deal_three = gen_poit_three(df2)

    kline_scatter = kline.overlap(scatter_deal_one)
    kline_scatter = kline_scatter.overlap(scatter_deal_two)
    kline_scatter = kline_scatter.overlap(scatter_deal_three)

    grid_chart = Grid(init_opts=opts.InitOpts(
        width="1000px",
        height="700px",
        animation_opts=opts.AnimationOpts(animation=False),
    ))
    grid_chart.add(
        kline_scatter,
        grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", height="45%"),
    )
    grid_chart.add(
        line_rsi,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="57%",
                                height="17%"),
    )

    grid_chart.add(
        line_atr,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="76%",
                                height="17%"),
    )

    grid_chart.render("k_deal_rsi_atr.html")
def image_host_resource(doc_path, hosts_metrics, host):
    options = opts.InitOpts(js_host=os.path.join(os.getcwd(), "scripts/javascript/"),
                            animation_opts=opts.AnimationOpts(animation=False))
    line1 = (
        Line(options)
            .add_xaxis(hosts_metrics[host['ip']]['metrics']['datetime'])
            .add_yaxis("CPU", hosts_metrics[host['ip']]['metrics']['cpu'], is_symbol_show=False, is_smooth=True,
                       areastyle_opts=opts.AreaStyleOpts(color=utils.JsCode(
                           "new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'rgb(255,158,68)'},{offset:1,color:'rgb(255,70,131)'}])"),
                           opacity=0.5))
            .add_yaxis("Memory", hosts_metrics[host['ip']]['metrics']['memory'], is_symbol_show=False, is_smooth=True)
            .set_series_opts(linestyle_opts=opts.LineStyleOpts(width=2))
            .set_global_opts(
            title_opts=opts.TitleOpts(title="主机资源使用率 (%s)" % (host['ip']),
                                      title_textstyle_opts=opts.TextStyleOpts(font_size=13),
                                      subtitle=" 数据来源-健康度平台"),
            xaxis_opts=opts.AxisOpts(type_="time"),
            yaxis_opts=opts.AxisOpts(
                axislabel_opts=opts.LabelOpts(formatter=utils.JsCode("function(val){return val + '%';}")))
        )
    )

    line2 = (
        Line(options)
            .add_xaxis(hosts_metrics[host['ip']]['metrics']['datetime'])
            .add_yaxis("Process", hosts_metrics[host['ip']]['metrics']['process'], is_symbol_show=False, is_smooth=True,
                       areastyle_opts=opts.AreaStyleOpts(color=utils.JsCode(
                           "new echarts.graphic.LinearGradient(0,0,0,1,[{offset:0,color:'#fff'},{offset:1,color:'#61a0a8'}])"),
                           opacity=0.5)
                       )
            .set_series_opts(linestyle_opts=opts.LineStyleOpts(width=2))
            .set_global_opts(
            xaxis_opts=opts.AxisOpts(type_="time", position="top", axislabel_opts=opts.LabelOpts(is_show=False)),
            yaxis_opts=opts.AxisOpts(is_inverse=True),
            title_opts=opts.TitleOpts(title="应用运行数量(所有)", pos_bottom="0%",
                                      title_textstyle_opts=opts.TextStyleOpts(font_size=13)),
            legend_opts=opts.LegendOpts(pos_bottom="0%")
        )
    )

    grid = (
        Grid(options)
            .add(line1, grid_opts=opts.GridOpts(pos_top=50, pos_left=50, pos_right=50, pos_bottom="50%"))
            .add(line2, grid_opts=opts.GridOpts(pos_top="58%", pos_left=50, pos_right=50, pos_bottom=30))
    )

    make_snapshot(snapshot, grid.render(os.path.join(doc_path, "render_%s.html" % (host['ip'].replace(".", "_")))),
                  os.path.join(doc_path, "host_res_%s.png" % (host['ip'].replace(".", "_"))), pixel_ratio=1, delay=1,
                  is_remove_html=True)
Exemplo n.º 28
0
def type_base() -> Bar:
    results1 = types.find()
    dis1 = []
    for result in results1:
        dis1.append(result['distance'])
    c = (
        Bar(init_opts=opts.InitOpts(
            animation_opts=opts.AnimationOpts(
                animation_delay=500,
                animation_easing="elasticOut",  # 延时动画效果
                animation_duration_update=1000), )).add_xaxis(
                    ["喜剧", "动作", "家庭", "战争",
                     "惊悚"]).add_yaxis("评分差距", dis1).set_global_opts(
                         title_opts=opts.TitleOpts(title="类型")))
    return c
Exemplo n.º 29
0
 def draw_network(self, layout="force", render=False):
     """将网络可视化输出"""
     if self.scale > 10000:  # 对于太大的网络,可视化意义不大且效率极低,故只对小型网络进行可视化
         raise ValueError("网络规模太大("+str(self.scale)+"),不支持可视化!请抽取更小的子网络进行可视化")
     g = self.network
     if self._community is None:
         self._community = community.best_partition(g)
     if layout.lower() != 'force' and layout.lower() != 'circular':
         raise ValueError("没有这种布局!布局请选择force或circular")
     # 获取节点名称映射
     names = nx.get_node_attributes(g, 'name')
     nodes = [{'name': names[n], 'symbolSize': (math.log2(nx.degree(g, n, weight=self.weight_type)+1))*6,
               'category': self._community[n], 'value':nx.degree(g, n, weight=self.weight_type)}
              for n in g.nodes()]
     links = [{'source': names[e[0]], 'target': names[e[1]]} for e in g.edges(data=True)]
     categories = [{'category': self._community[n], 'name': self._community[n]} for n in g.nodes()]
     graph = (
         Graph(
             init_opts=opts.InitOpts(
                 width="1200px", height="1000px",
                 animation_opts=opts.AnimationOpts(
                     animation=False,
                     animation_threshold=10,
                     animation_duration=1,
                     ),
                 )
             )
         .add(
             "",
             nodes=nodes,
             links=links,
             categories=categories,
             repulsion=50,
             linestyle_opts=opts.LineStyleOpts(curve=0.2),
             label_opts=opts.LabelOpts(is_show=False),
             )
         .set_global_opts(
             legend_opts=opts.LegendOpts(is_show=True, orient="vertical", pos_left="2%", pos_top="10%"),
             )
         )
     if render:
         graph.render(self.net_type+'.html')
     return graph
Exemplo n.º 30
0
def gen_line_plot(
    stock_data: pd.DataFrame,
    chart_data: typing.Dict[str, typing.List[typing.List[typing.Union[float,
                                                                      int]]]],
) -> Line:
    ma_items = [5, 10, 20, 60]
    line = Line(init_opts=opts.InitOpts(animation_opts=opts.AnimationOpts(
        animation=False), )).add_xaxis(xaxis_data=chart_data["categoryData"])
    for ma in ma_items:
        line.add_yaxis(
            series_name=f"MA{ma}",
            y_axis=ta.trend.sma_indicator(stock_data["close"], ma).round(2),
            is_smooth=True,
            is_symbol_show=False,
            is_hover_animation=False,
            linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
    line.set_global_opts(xaxis_opts=opts.AxisOpts(type_="category"))
    return line