Exemple #1
0
def vtradevolume(cftable, freq="D"):
    """
    aid function on visualization of trade summary

    :param cftable: cftable (pandas.DataFrame) with at least date and cash columns
    :param freq: one character string, frequency label, now supporting D for date,
        W for week and M for month, namely the trade volume is shown based on the time unit
    :returns: the Bar object
    """
    ### WARN: datazoom and time conflict, sliding till 1970..., need further look into pyeacharts
    ### very unsatisfied about current visualize effect, and it seems the order of add and set option matters a lot
    if freq == "D":
        datedata = [d.to_pydatetime() for d in cftable["date"]]
        selldata = [
            [row["date"].to_pydatetime(), row["cash"]]
            for _, row in cftable.iterrows()
            if row["cash"] > 0
        ]
        buydata = [
            [row["date"].to_pydatetime(), row["cash"]]
            for _, row in cftable.iterrows()
            if row["cash"] < 0
        ]
    elif freq == "W":
        cfmerge = cftable.groupby([cftable["date"].dt.year, cftable["date"].dt.week])[
            "cash"
        ].sum()
        datedata = [
            dt.datetime.strptime(str(a) + "4", "(%Y, %W)%w")
            for a, _ in cfmerge.iteritems()
        ]
        selldata = [
            [dt.datetime.strptime(str(a) + "4", "(%Y, %W)%w"), b]
            for a, b in cfmerge.iteritems()
            if b > 0
        ]
        buydata = [
            [dt.datetime.strptime(str(a) + "4", "(%Y, %W)%w"), b]
            for a, b in cfmerge.iteritems()
            if b < 0
        ]
    elif freq == "M":
        cfmerge = cftable.groupby([cftable["date"].dt.year, cftable["date"].dt.month])[
            "cash"
        ].sum()
        datedata = [
            dt.datetime.strptime(str(a) + "15", "(%Y, %m)%d")
            for a, _ in cfmerge.iteritems()
        ]
        selldata = [
            [dt.datetime.strptime(str(a) + "15", "(%Y, %m)%d"), b]
            for a, b in cfmerge.iteritems()
            if b > 0
        ]
        buydata = [
            [dt.datetime.strptime(str(a) + "15", "(%Y, %m)%d"), b]
            for a, b in cfmerge.iteritems()
            if b < 0
        ]
    else:
        raise ParserFailure("no such freq tag supporting")

    bar = Bar()
    bar.add_xaxis(datedata)
    bar.add_yaxis(series_name="卖出", yaxis_data=selldata, category_gap="90%")
    bar.add_yaxis(series_name="买入", yaxis_data=buydata, category_gap="90%")

    bar.set_global_opts(
        xaxis_opts=AxisOpts(type_="time"),
        datazoom_opts=[DataZoomOpts(range_start=99, range_end=100)],
    )

    return bar.render_notebook()
Exemple #2
0
        "2021-12-24",
    ],
}

connection_errors = (
    HttpStatusError,
    ConnectionResetError,
    requests.exceptions.RequestException,
    requests.exceptions.ConnectionError,
    requests.exceptions.SSLError,
    JSONDecodeError,
)

line_opts = {
    "datazoom_opts": [
        DataZoomOpts(is_show=True, type_="slider", range_start=50, range_end=100),
        DataZoomOpts(
            is_show=True,
            type_="slider",
            orient="vertical",
            range_start=50,
            range_end=100,
        ),
    ],
    "tooltip_opts": TooltipOpts(
        is_show=True, trigger="axis", trigger_on="mousemove", axis_pointer_type="cross"
    ),
}

heatmap_opts = {
    "visualmap_opts": VisualMapOpts(
Exemple #3
0
def total_trend(day,shdeath,shcured,shsum,shpending) -> Line:
    line = (
        Line(init_opts=InitOpts())
        .add_xaxis(day)
        # .add_yaxis("全国死亡",y_axis=death,is_connect_nones=True,is_smooth=True)
   
        .add_yaxis(
            '死亡',shdeath,symbol_size=10,color='black',
            itemstyle_opts=ItemStyleOpts(color='black'),
            label_opts=LabelOpts(is_show=False),
            areastyle_opts=AreaStyleOpts(opacity=0.5,color='black'),
            stack=1,is_connect_nones=True,is_smooth=True
            )
        .add_yaxis(
            '治愈',shcured,symbol_size=10,color='LimeGreen',
            itemstyle_opts=ItemStyleOpts(color='LimeGreen'),
            label_opts=LabelOpts(font_size=15,color='ForestGreen'),
            areastyle_opts=AreaStyleOpts(opacity=0.5,color='LimeGreen'),
            stack=1,is_connect_nones=True,is_smooth=True
            )
        .add_yaxis(
            '确诊',shsum,symbol_size=10,color='Orange',
            itemstyle_opts=ItemStyleOpts(color='Orange'),
            label_opts=LabelOpts(font_size=15,color='DarkOrange',font_weight='bold'),
            areastyle_opts=AreaStyleOpts(opacity=0.5,color='Orange'),
            stack=1,is_connect_nones=True,is_smooth=True
            )
        .add_yaxis(
            '疑似',shpending,symbol_size=10,color='LightSkyBlue',
            itemstyle_opts=ItemStyleOpts(color='LightSkyBlue'),
            label_opts=LabelOpts(font_size=15,color='DarkBlue'),
            areastyle_opts=AreaStyleOpts(opacity=0.5,color='LightSkyBlue'),
            stack=1,is_connect_nones=True,is_smooth=True
            )
        .set_global_opts(
            title_opts=TitleOpts(
                # title=title,
                # pos_left='10%',
                # pos_top='-10%',
                ),
            # tooltip_opts=TooltipOpts(formatter="{b} {a}\n {c}人"),
            datazoom_opts=[
                DataZoomOpts(range_start=40,range_end=100,xaxis_index=[0, 1],),
                DataZoomOpts(range_start=40,range_end=100,xaxis_index=[0, 1],type_='inside'),
                ],
            xaxis_opts=AxisOpts(name_gap=50),
            legend_opts=LegendOpts(
                pos_top='top',pos_left='10%',
                textstyle_opts=TextStyleOpts(font_size=30),
                orient='horizontal',legend_icon='rect'
                ),
            tooltip_opts=TooltipOpts(textstyle_opts=TextStyleOpts(font_size=30)),
            graphic_opts=GraphicGroup(
                graphic_item=GraphicItem(left="12%",top="11%"),
                children=[
                    GraphicRect(
                        graphic_item=GraphicItem(z=0,left="center",top="middle"),
                        graphic_shape_opts=GraphicShapeOpts(width=150, height=90),
                        graphic_basicstyle_opts=GraphicBasicStyleOpts(
                            fill="#fff",
                            stroke="black",
                            line_width=3,
                            )
                        ),                                        
                    GraphicText(
                        graphic_item=GraphicItem(left="center",top="middle",z=0),
                        graphic_textstyle_opts=GraphicTextStyleOpts(
                            text=f"确诊{shsum[-1]}人\n\n疑似{shpending[-1]}人",
                            font="bolder 20px sans-serif",
                            graphic_basicstyle_opts=GraphicBasicStyleOpts(fill="#333")
                            )
                        )
                    ]
                )
            )
        )
        # line.overlap(bar)
    return line