Example #1
0
def hist_order_base():
    # 数据查询
    dataX, dataY = order_sum_query()
    # 对象声明
    # 订单数据
    c = (Line(init_opts=opts.InitOpts(
        theme=ThemeType.LIGHT)).add_xaxis(dataX).add_yaxis(
            "订单量", dataY, is_smooth=True).set_global_opts(
                title_opts=opts.TitleOpts(title="日订单量历史数据趋势图"),
                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),
            ))
    return c
Example #2
0
def line_areastyle_boundary_gap() -> Line:
    a = (Line().add_xaxis(x1).add_yaxis("拉美", 拉美GDP, is_smooth=True).add_yaxis(
        "美国", 美国GDP, is_smooth=True).add_yaxis(
            "世界", 世界GDP, color="#5793f3", is_smooth=True).set_series_opts(
                areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
                label_opts=opts.LabelOpts(is_show=False),
            ).set_global_opts(
                title_opts=opts.TitleOpts(title="1971-1990GDP增长率"),
                toolbox_opts=opts.ToolboxOpts(),
                datazoom_opts=opts.DataZoomOpts(),
                xaxis_opts=opts.AxisOpts(
                    axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                    is_scale=False,
                    boundary_gap=False,
                ),
            ))
    return a
Example #3
0
def books_pubdate_scatter(id, num) -> Scatter:
    (time,times,num) = books_pubdate(id, num)
    if time == 0:
        return 0
    x_data = list(map(str, times.keys()))
    y_data = list(map(str, times.values()))

    c = (
        Scatter()  # init_opts=opts.InitOpts(width="1600px", height="1000px")
        .add_xaxis(xaxis_data=x_data)
        .add_yaxis(
            series_name="图书数",
            y_axis=y_data,
            symbol_size=20,
            label_opts=opts.LabelOpts(is_show=False),
        )
        .set_series_opts()
        .set_global_opts(
            title_opts=opts.TitleOpts(title="图书发行趋势", subtitle="数据量:" + str(num),),
            xaxis_opts=opts.AxisOpts(
                splitline_opts=opts.SplitLineOpts(is_show=True),
                name="图书发行时间"
            ),
            yaxis_opts=opts.AxisOpts(
                #             type_="value",
                name="图书数量",
                name_gap=50,
                name_rotate=90,
                name_location="center",
                axistick_opts=opts.AxisTickOpts(is_show=True),
                splitline_opts=opts.SplitLineOpts(is_show=True),
            ),
            tooltip_opts=opts.TooltipOpts(is_show=True),
            visualmap_opts=opts.VisualMapOpts(type_="size", max_=5, min_=1),
            toolbox_opts=opts.ToolboxOpts(is_show=True,pos_left="95%",
                                          feature={
                                              "dataZoom": {"yAxisIndex": "none"},
                                              "dataView": {},
                                              "restore": {},
                                              "saveAsImage": {},
                                          },
                                          ),
        )
        .dump_options_with_quotes()
    )
    return c
Example #4
0
def drawtable(request):
    json_data = request.body.decode('utf-8')
    info = json.loads(json_data)
    table_name = info.get('table_name', '').strip()

    # line_path = 'mycharts/render/tabledata/charts_%s.html' % table_name.split('.')[1]
    # 部署到apache服务器后需要使用绝对路径
    line_path = os.path.join(
        app_dir, 'render/tabledata/charts_%s.html' % table_name.split('.')[1])
    if not os.path.exists(
            line_path) or time.time() - os.path.getmtime(line_path) > 86400:
        table = get_object_or_404(TableData, table_name=table_name)
        line_name = table.table_name
        table_data = table.table_data
        x_data = table_data.get("total_diff_rate").keys()
        y_data = table_data.get("total_diff_rate").values()
        line = (charts.Line().set_global_opts(
            tooltip_opts=opts.TooltipOpts(is_show=False),
            xaxis_opts=opts.AxisOpts(type_="category"),
            yaxis_opts=opts.AxisOpts(
                type_="value",
                axistick_opts=opts.AxisTickOpts(is_show=True),
                splitline_opts=opts.SplitLineOpts(is_show=True),
            ),
            title_opts=opts.TitleOpts(
                title="差异比",
                subtitle="单位1")).add_xaxis(xaxis_data=x_data).add_yaxis(
                    series_name=line_name,
                    y_axis=y_data,
                    symbol="circle",
                    itemstyle_opts=opts.ItemStyleOpts(border_color='#fff'),
                    markpoint_opts=opts.MarkPointOpts(
                        label_opts=opts.LabelOpts(color='#fff'),
                        data=[
                            opts.MarkPointItem(type_='max', name='最大值'),
                            opts.MarkPointItem(type_='min', name='最小值'),
                            opts.MarkLineItem(type_="average", name="平均值")
                        ]),
                    markline_opts=opts.MarkLineItem(type_='average'),
                    is_symbol_show=True,
                    label_opts=opts.LabelOpts(is_show=False),
                    is_connect_nones=True))
        line.render(line_path)

    chart = open(line_path).read()
    return HttpResponse(chart)
Example #5
0
def describeLineArea(ctime, trans, comment, like):
    c = (Line().add_xaxis(ctime).add_yaxis(
        "转发量", trans,
        is_smooth=True).add_yaxis("评论量", comment, is_smooth=True).add_yaxis(
            "点赞量", like, is_smooth=True).set_series_opts(
                areastyle_opts=opts.AreaStyleOpts(opacity=0.3),
                label_opts=opts.LabelOpts(is_show=False),
            ).set_global_opts(
                title_opts=opts.TitleOpts(title="实时趋势图"),
                xaxis_opts=opts.AxisOpts(
                    axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                    is_scale=False,
                    boundary_gap=False,
                ),
                tooltip_opts=opts.TooltipOpts(trigger="axis",
                                              axis_pointer_type="line")))
    return c
    def drawLine(self):
        df = pd.read_csv('energySpider/homec(1).csv')
        df["时间"] = pd.to_datetime(df['时间'], unit='s')
        df_time = df["时间"].astype(str)
        df = df["房屋整体能耗 [kW]"]
        df = df.tail(15)
        df_time = df_time.tail(15)
        print(df_time)
        # 绘制折线图
        difference = df
        heming = df_time

        x_data = heming.values
        y_data = difference.values
        subdue = (Line().set_global_opts(
            title_opts=opts.TitleOpts(
                title="总能耗折线图",
                title_textstyle_opts=opts.TextStyleOpts(color="black")),
            legend_opts=opts.LegendOpts(textstyle_opts=opts.TextStyleOpts(
                color="black")),
            tooltip_opts=opts.TooltipOpts(is_show=False),
            xaxis_opts=opts.AxisOpts(
                type_="category",
                axislabel_opts=opts.LabelOpts(rotate=30, color="black"),
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(color="black"))),
            yaxis_opts=opts.AxisOpts(
                type_="value",
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(color="black")),
                axislabel_opts=opts.LabelOpts(color="black"),
                axistick_opts=opts.AxisTickOpts(is_show=True),
                splitline_opts=opts.SplitLineOpts(is_show=True),
            ),
        ).add_xaxis(xaxis_data=x_data).add_yaxis(
            series_name="能耗(kW)",
            y_axis=y_data,
            symbol="emptyCircle",
            is_symbol_show=True,
            label_opts=opts.LabelOpts(is_show=False),
            color='#9AECDB',
            symbol_size=5,
            is_smooth=False,
            is_hover_animation=True))
        return subdue
Example #7
0
def draw_pic(profitArray):
    x_data = [x['time'] for x in profitArray]
    y_axis = [x['profit_rate'] for x in profitArray]
    (Line().add_xaxis(xaxis_data=x_data).add_yaxis(
        series_name="收益率",
        stack="总量",
        y_axis=y_axis,
        label_opts=opts.LabelOpts(is_show=False),
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="策略收益率图(海龟策略+多因子)"),
        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),
    ).render("策略收益率(海龟策略+多因子).html"))
Example #8
0
def analysis_struct():
    # 处理数据
    x_data = pdata['年份'].map(lambda x: "%d" % x).tolist()
    y_data1 = pdata['0-14岁人口(万人)'].map(lambda x: "%.2f" % x).tolist()
    y_data2 = pdata['15-64岁人口(万人)'].map(lambda x: "%.2f" % x).tolist()
    y_data3 = pdata['65岁及以上人口(万人)'].map(lambda x: "%.2f" % x).tolist()

    # 人口结构折线图
    line = Line()
    line.add_xaxis(x_data)
    line.add_yaxis('0-14岁人口',
                   y_data1,
                   label_opts=opts.LabelOpts(is_show=False))
    line.add_yaxis('15-64岁人口',
                   y_data2,
                   label_opts=opts.LabelOpts(is_show=False))
    line.add_yaxis('65岁及以上人口',
                   y_data3,
                   label_opts=opts.LabelOpts(is_show=False))
    line.set_global_opts(
        title_opts=opts.TitleOpts(title="人口结构",
                                  pos_bottom="bottom",
                                  pos_left="center"),
        xaxis_opts=opts.AxisOpts(
            name='年份',
            name_location='end',
            type_="category",
            # axislabel_opts=opts.LabelOpts(is_show=True, color="#000", interval=0, rotate=90),
            axistick_opts=opts.AxisTickOpts(is_show=True,
                                            is_align_with_label=True),
            axispointer_opts=opts.AxisPointerOpts(
                type_="shadow", label=opts.LabelOpts(is_show=True))),
        # y轴相关选项设置
        yaxis_opts=opts.AxisOpts(name='人口数(万人)',
                                 type_="value",
                                 position="left",
                                 axislabel_opts=opts.LabelOpts(is_show=True)),
        legend_opts=opts.LegendOpts(is_show=True))

    # 渲染图像,将多个图像显示在一个html中
    # DraggablePageLayout表示可拖拽
    page = Page(layout=Page.DraggablePageLayout)
    page.add(line)
    page.render('population_struct.html')
Example #9
0
    def kdj(self, echarts_data):
        # KDJ
        kdj_line = (
            Line()
                .add_xaxis(xaxis_data=echarts_data['date'])
                .add_yaxis(
                series_name="K",
                y_axis=echarts_data['kdj_k'],
                is_symbol_show=False,  # 去掉折线上的小圆点
                label_opts=opts.LabelOpts(is_show=False),
            )
                .add_yaxis(
                series_name="D",
                y_axis=echarts_data["kdj_d"],
                is_symbol_show=False,  # 去掉折线上的小圆点
                label_opts=opts.LabelOpts(is_show=False),
            )
                .add_yaxis(
                series_name="J",
                y_axis=echarts_data["kdj_j"],
                is_symbol_show=False,  # 去掉折线上的小圆点
                label_opts=opts.LabelOpts(is_show=False),
                # markline_opts=opts.MarkLineOpts(
                #     data=[100]
                # ),
            )
                .set_global_opts(
                xaxis_opts=opts.AxisOpts(
                    type_="category",
                    grid_index=2,
                    axislabel_opts=opts.LabelOpts(is_show=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,
                ),
                # title_opts=opts.TitleOpts(subtitle="KDJ"),
                title_opts=opts.TitleOpts(subtitle="KDJ", pos_top="62%"),    # 标题
                legend_opts=opts.LegendOpts(pos_top="58%"),  # 图例位置
            )
        )
        return kdj_line
Example #10
0
def bottom_all(width,height,title,date,view,follower,likes,video_count):
    c = (
        Line(init_opts=opts.InitOpts(theme=ThemeType.CHALK,width=width,height=height))
        .add_xaxis(date)
        .add_yaxis(
            series_name="被关注数",
            stack="总量",
            y_axis=follower,
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .add_yaxis(
            series_name="点赞数",
            stack="总量",
            y_axis=likes,
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .add_yaxis(
            series_name="视频总数",
            stack="总量",
            y_axis=video_count,
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .add_yaxis(
            series_name="播放总数",
            stack="总量",
            y_axis=view,
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .set_global_opts(
            tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
            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),
        )

    )
    return c
Example #11
0
def conf_new_base() -> Line:
    # 静态数据
    # df = pd.read_excel("data/linedata.xlsx",
    #                     usecols=[1],
    #                     names=None)  # 读取项目名称列,不要列名
    # df_li = df.values.tolist()
    # dataY1 = []
    # dataY2 = []
    # dataX = []
    # for s_li in df_li:
    #     dataY1.append(s_li[0])
    #     dataY2.append(s_li[0])
    #     dataX.append(s_li[0])
    # print(result)

    dataY1 = [
        77, 259, 769, 1737, 2590, 3887, 3399, 2478, 5090, 2048, 394, 648, 406,
        427, 125, 143, 40, 15
    ]
    dataY2 = [
        27, 680, 3806, 4148, 4562, 3971, 4214, 3536, 2450, 1563, 1277, 882,
        439, 248, 129, 102, 60, 33
    ]
    dataX = [
        '2020.01.21', '2020.01.24', '2020.01.27', '2020.01.30', '2020.02.02',
        '2020.02.05', '2020.02.08', '2020.02.11', '2020.02.14', '2020.02.17',
        '2020.02.20', '2020.02.23', '2020.02.26', '2020.02.29', '2020.03.03',
        '2020.03.06', '2020.03.09', '2020.03.11'
    ]
    c = (Line(init_opts=opts.InitOpts(
        theme=ThemeType.LIGHT)).add_xaxis(dataX).add_yaxis(
            "新增确诊", dataY1, is_smooth=True).add_yaxis(
                "新增疑似", dataY2, is_smooth=True).set_global_opts(
                    title_opts=opts.TitleOpts(title="全国疫情新增确诊/疑似趋势图"),
                    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),
                ))
    return c
Example #12
0
def draw_degree_histogram():
    degree_histogram = nx.degree_histogram(G)
    c = (Line().add_xaxis([x for x in range(len(degree_histogram))]).add_yaxis(
        "Number of authors", degree_histogram, is_smooth=True).set_series_opts(
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
            markpoint_opts=opts.MarkPointOpts(data=[
                opts.MarkPointItem(type_="max", name="Maximum"),
            ]),
        ).set_global_opts(
            title_opts=opts.TitleOpts(title="Degree Histogram"),
            datazoom_opts=opts.DataZoomOpts(),
            xaxis_opts=opts.AxisOpts(
                name="Degree",
                axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                is_scale=False,
                boundary_gap=False,
            ),
        ).render("Degree_Histogram.html"))
Example #13
0
def get_line(data_x, data_y, line_name=""):
    line = Line()
    line.set_global_opts(
        tooltip_opts=opts.TooltipOpts(trigger="axis"),
        xaxis_opts=opts.AxisOpts(type_="category"),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
    )
    line.add_xaxis(xaxis_data=data_x)
    line.add_yaxis(series_name=line_name,
                   y_axis=data_y,
                   symbol="emptyCircle",
                   is_symbol_show=True,
                   label_opts=opts.LabelOpts(is_show=False),
                   is_smooth=True)
    return line
Example #14
0
def line_center(width,height,title,date,view):
    c = (
        Line(init_opts=opts.InitOpts(theme=ThemeType.CHALK,width=width,height=height))
        .add_xaxis(date)
        .add_yaxis("哔哩哔哩", view)
        # .add_yaxis("YouTube", [3,2,55,4,5])
        .set_series_opts(
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=True),
        )
        .set_global_opts(
            xaxis_opts=opts.AxisOpts(
                axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                is_scale=False,
                boundary_gap=False,
            ),
        )
    )
    return c
Example #15
0
def set_lagou_education(education):
    """
    绘制拉勾网经验学历要求图,采用象形图
    :return:
    """
    experienced = ['{}+{}'.format(i.split('/')[1], i.split('/')[0]).replace('经验', '') for i in
                   [e[0] for e in education]]
    counts = [i[1] for i in education]
    pictorialbar = (
        PictorialBar(init_opts=opts.InitOpts(width='700px', height='500px'))
            .add_xaxis(experienced)
            .add_yaxis("最新拉勾网20000+职位数据的学历经验门槛",
                       counts,
                       symbol=SymbolType.DIAMOND,
                       symbol_repeat=True,
                       symbol_repeat_direction='end',
                       is_symbol_clip=True,
                       color='#DEB887',
                       )
            .reversal_axis()  # 翻转
            .set_global_opts(title_opts=opts.TitleOpts(title='拉勾网30000+招聘的企业的工作经验+学历门槛'),
                             xaxis_opts=opts.AxisOpts(is_show=False),
                             yaxis_opts=opts.AxisOpts(axisline_opts=opts.AxisLineOpts(is_show=False),
                                                      axistick_opts=opts.AxisTickOpts(is_show=False),
                                                      axislabel_opts=opts.LabelOpts(margin=-2)
                                                      ),
                             legend_opts=opts.LegendOpts(pos_left='right')
                             )
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False,
                                                       position='right'),
                             markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(name='最大值',
                                                                                        type_='max',
                                                                                        # value_index=0,
                                                                                        ),
                                                                     opts.MarkPointItem(name='最小值',
                                                                                        type_='min',
                                                                                        ),
                                                                     ]
                                                               ),
                             )
    )
    return pictorialbar
Example #16
0
def draw_degree():
    degree = nx.degree(G)
    degree_sort = sorted(degree, key=lambda x: x[1], reverse=True)
    e0 = [
        opts.BarItem(name=G.nodes[degree_sort[0][0]], value=degree_sort[0][1])
    ]
    e1 = [
        opts.BarItem(name=G.nodes[x[0]]['name'], value=x[1])
        for x in degree_sort if G.nodes[x[0]]['E_numbers'] == 1
    ][:50]
    e2 = [
        opts.BarItem(name=G.nodes[x[0]]['name'], value=x[1])
        for x in degree_sort if G.nodes[x[0]]['E_numbers'] == 2
    ][:50]

    xaxis = [x + 1 for x in range(50)]
    c = (Bar().add_xaxis(xaxis).add_yaxis(
        "Erdos_number is 0",
        e0,
        category_gap=0,
        itemstyle_opts=opts.ItemStyleOpts(color='#d48265'),
        gap="0%").add_yaxis(
            "Erdos_number is 1",
            e1,
            category_gap=0,
            itemstyle_opts=opts.ItemStyleOpts(color='#749f83'),
            gap="0%").add_yaxis(
                "Erdos_number is 2", e2, category_gap=0,
                gap="0%").set_series_opts(
                    label_opts=opts.LabelOpts(is_show=False),
                    axisline_opts=opts.AxisOpts(interval=1),
                    markline_opts=opts.MarkLineOpts(data=[
                        opts.MarkLineItem(type_="average", name="Average"),
                    ]),
                ).set_global_opts(
                    title_opts=opts.TitleOpts(title="Top 50 degree authors"),
                    datazoom_opts=opts.DataZoomOpts(),
                    yaxis_opts=opts.AxisOpts(
                        axistick_opts=opts.AxisTickOpts(is_show=True),
                        splitline_opts=opts.SplitLineOpts(is_show=True),
                    ),
                ).render("bar_stack1.html"))
Example #17
0
def mouth_article(biz):
    begin_date = (datetime.datetime.now() -
                  relativedelta(months=+1)).strftime("%Y-%m-%d")
    date_list = getBetweenDay(begin_date=begin_date)

    data_list = [
        WechatArticleList.query.filter_by(__biz=biz).filter(
            and_(
                extract(
                    'year',
                    WechatArticleList.publish_time) == str(date).split('-')[0],
                extract(
                    'month',
                    WechatArticleList.publish_time) == str(date).split('-')[1],
                extract(
                    'day',
                    WechatArticleList.publish_time) == str(date).split('-')[2],
            )).count() for date in date_list
    ]

    c = (Line().add_xaxis(xaxis_data=date_list).add_yaxis(
        "文章数",
        data_list,
        is_smooth=True,
        color='#66CDAA',
        label_opts=opts.LabelOpts(is_show=False)).set_series_opts(
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            markline_opts=opts.MarkLineOpts(data=[
                opts.MarkLineItem(type_="average", name="平均值"),
            ]),
        ).set_global_opts(
            title_opts=opts.TitleOpts(title="月发布文章统计",
                                      pos_left='43%',
                                      pos_top='8%'),
            xaxis_opts=opts.AxisOpts(
                axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                is_scale=False,
                boundary_gap=False,
            ),
            legend_opts=opts.LegendOpts(is_show=False),
        ))
    return c
def show_scatter():
    scatter = (
        Scatter(init_opts=opts.InitOpts(width="1600px", height="1000px")).
        add_xaxis(xaxis_data=co_friend_count).add_yaxis(
            series_name="Covid",
            y_axis=covid_polarity,
            symbol="triangle",
            symbol_size=15,
            label_opts=opts.LabelOpts(is_show=False),
        ).add_xaxis(xaxis_data=cr_friend_count).add_yaxis(
            series_name="Crime",
            y_axis=crime_polarity,
            symbol="circle",
            symbol_size=15,
            label_opts=opts.LabelOpts(is_show=False),
        ).set_series_opts().set_global_opts(
            title_opts=opts.TitleOpts(
                title="Twitter Friend Count VS Polarity"),
            xaxis_opts=opts.AxisOpts(
                name='Friend Count',
                name_location='middle',
                name_gap=20,
                type_="value",
                splitline_opts=opts.SplitLineOpts(is_show=True)),
            yaxis_opts=opts.AxisOpts(
                name='Polarity',
                name_location='middle',
                name_gap=20,
                type_="value",
                axistick_opts=opts.AxisTickOpts(is_show=True),
                splitline_opts=opts.SplitLineOpts(is_show=True),
            ),
            # tooltip_opts=opts.TooltipOpts(is_show=False),
            toolbox_opts=opts.ToolboxOpts(),
            visualmap_opts=opts.VisualMapOpts(
                type_="color",
                max_=1,
                min_=-1,
                range_text=['Positive', 'Negative'],
            ),
        ))
    return scatter
Example #19
0
def pictorialbar_base() -> PictorialBar:
    c = (PictorialBar().add_xaxis(location).add_yaxis(
        "",
        values,
        label_opts=opts.LabelOpts(is_show=False),
        symbol_size=18,
        symbol_repeat="fixed",
        symbol_offset=[0, 0],
        is_symbol_clip=True,
        symbol=SymbolType.ROUND_RECT,
    ).reversal_axis().set_global_opts(
        title_opts=opts.TitleOpts(title="PictorialBar-各省份人口数量(虚假数据)"),
        xaxis_opts=opts.AxisOpts(is_show=False),
        yaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(
                opacity=0)),
        ),
    ))
    return c
Example #20
0
File: app.py Project: zhuby1973/map
def net_io_line() -> Line:
    net_io()

    c = (Line().add_xaxis(net_io_dict['net_io_time']).add_yaxis(
        "发送字节数", net_io_dict['net_io_sent'], is_smooth=True).add_yaxis(
            "接收字节数", net_io_dict['net_io_recv'],
            is_smooth=True).set_series_opts(
                areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
                label_opts=opts.LabelOpts(is_show=False),
            ).set_global_opts(
                title_opts=opts.TitleOpts(title="网卡IO", pos_left="center"),
                xaxis_opts=opts.AxisOpts(
                    axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                    is_scale=False,
                    boundary_gap=False,
                ),
                yaxis_opts=opts.AxisOpts(type_="value", name='B/2S'),
                legend_opts=opts.LegendOpts(pos_left="left"),
            ))
    return c
Example #21
0
 def draw(self, indexs, values, filename):
     c = (PictorialBar().add_xaxis(indexs).add_yaxis(
         "",
         values,
         label_opts=opts.LabelOpts(is_show=False),
         symbol_size=18,
         symbol_repeat="fixed",
         symbol_offset=[0, 0],
         is_symbol_clip=True,
         symbol=SymbolType.ROUND_RECT,
     ).reversal_axis().set_global_opts(
         title_opts=opts.TitleOpts(title="报道香港新闻热门博主前十名"),
         xaxis_opts=opts.AxisOpts(is_show=False),
         yaxis_opts=opts.AxisOpts(
             axistick_opts=opts.AxisTickOpts(is_show=False),
             axisline_opts=opts.AxisLineOpts(
                 linestyle_opts=opts.LineStyleOpts(opacity=0)),
         ),
     ))
     c.render(filename)
def line_areastyle_boundary_gap() -> Line:
    c = (
        Line()
        .add_xaxis(Faker.choose())
        .add_yaxis("商家A", Faker.values(), is_smooth=True)
        .add_yaxis("商家B", Faker.values(), is_smooth=True)
        .set_series_opts(
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Line-面积图(紧贴 Y 轴)"),
            xaxis_opts=opts.AxisOpts(
                axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                is_scale=False,
                boundary_gap=False,
            ),
        )
    )
    return c
Example #23
0
def draw_two(stock_profit, profit):
    x_data = [x['time'] for x in profit]
    #  策略收益
    y_axis = [x['profit_rate'] for x in profit]
    #  湾区涨幅
    y_stock_axis = [x['profit_rate'] for x in stock_profit]
    c = (Line().add_xaxis(xaxis_data=x_data).add_yaxis(
        "策略收益", y_axis, is_smooth=True).add_yaxis(
            "大湾区指数", y_stock_axis, is_smooth=True).set_series_opts(
                areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
                label_opts=opts.LabelOpts(is_show=False),
            ).set_global_opts(
                title_opts=opts.TitleOpts(title="湾区指数和策略对比图(最大夏普率)"),
                xaxis_opts=opts.AxisOpts(
                    axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                    is_scale=False,
                    boundary_gap=False,
                ),
                tooltip_opts=opts.TooltipOpts(trigger="axis"),
            ).render("../第二题/湾区指数和策略对比图(最大夏普率).html"))
Example #24
0
def pictorialbar_custom_symbol() -> PictorialBar:
    c = (PictorialBar().add_xaxis(location).add_yaxis(
        "",
        values,
        label_opts=opts.LabelOpts(is_show=False),
        symbol_size=22,
        symbol_repeat="fixed",
        symbol_offset=[0, -5],
        is_symbol_clip=True,
        symbol=symbols["boy"],
    ).reversal_axis().set_global_opts(
        title_opts=opts.TitleOpts(title="PictorialBar-自定义 Symbol"),
        xaxis_opts=opts.AxisOpts(is_show=False),
        yaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(
                opacity=0)),
        ),
    ))
    return c
Example #25
0
def show_showtime():
    data=select_data()
    # 折线图初始化
    line = Line(init_opts=opts.InitOpts(page_title="豆瓣电影-中外电影上映年份分布图"))
    # 横坐标
    line.add_xaxis(data[0])
    # 纵坐标
    line.add_yaxis("全球", data[1], color="#2f4554")
    line.add_yaxis("中国", data[2], color="#749f83")
    line.add_yaxis("美国", data[3], color="#c23531")
    line.set_series_opts(
        label_opts=opts.LabelOpts(is_show=False),
        # 标记最大值
        markpoint_opts=opts.MarkPointOpts(
            data=[
                opts.MarkPointItem(type_="max", name="最大值"),
            ]
        )
    )
    # 全局配置
    line.set_global_opts(
        # 标题
        title_opts=opts.TitleOpts(
            title="豆瓣电影-中外电影上映年份分布图", pos_left='center'),
        # 标签
        legend_opts=opts.LegendOpts(
            pos_left="620px", pos_top="28px"),
        # 水平滚动条
        datazoom_opts=opts.DataZoomOpts(),
        # 纵坐标设置
        yaxis_opts=opts.AxisOpts(
            # 显示坐标轴刻度
            axistick_opts=opts.AxisTickOpts(is_show=True),
            # 显示分割线
            splitline_opts=opts.SplitLineOpts(is_show=True)
        )
    )
    # 生成HTML
    html="pages/iframes/showtime.html"
    line.render("./templates/"+html)
    return html
Example #26
0
def article_day_num():
    today = datetime.datetime.strptime('2019-12-31', '%Y-%m-%d')
    date_list = [(today - datetime.timedelta(days=i)).strftime('%Y-%m-%d')
                 for i in range(365)]
    date_list.reverse()

    data_list = [
        WechatArticle.query.filter(
            and_(
                extract('year',
                        WechatArticle.publish_time) == str(date).split('-')[0],
                extract('month',
                        WechatArticle.publish_time) == str(date).split('-')[1],
                extract('day',
                        WechatArticle.publish_time) == str(date).split('-')[2],
            )).count() for date in date_list
    ]

    c = (Line({
        "width": "1500px",
        "height": "700px"
    }).add_xaxis(xaxis_data=date_list).add_yaxis(
        "文章数(篇)",
        data_list,
        is_smooth=True,
        color='#66CDAA',
        label_opts=opts.LabelOpts(is_show=False)).set_series_opts(
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5), ).set_global_opts(
                title_opts=opts.TitleOpts(title="2019年每天收录文章统计",
                                          pos_left='43%',
                                          pos_top='8%'),
                xaxis_opts=opts.AxisOpts(
                    axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                    is_scale=False,
                    boundary_gap=False,
                ),
                legend_opts=opts.LegendOpts(is_show=False),
            ))
    c.render(path='./static/year/article_day_num.html')
    print('生成每天收录文章统计')
    return c
Example #27
0
    def place_top(self):
        print('正在生成销售地Top10...')
        group_count = self.collection.aggregate([{
            '$group': {
                '_id': '$店铺地址',
                'count': {
                    '$sum': 1
                }
            }
        }])

        addr = []
        count = []
        sorted_list = sorted([list(item.values()) for item in group_count],
                             key=lambda x: x[-1],
                             reverse=True)
        for item in sorted_list[:10][::-1]:
            addr.append(item[0])
            count.append(item[1])

        c = (PictorialBar().add_xaxis(addr).add_yaxis(
            '',
            count,
            label_opts=opts.LabelOpts(is_show=False),
            symbol_size=16,
            symbol_repeat='fixed',
            symbol_offset=[0, 0],
            is_symbol_clip=True,
            symbol=SymbolType.ROUND_RECT,
        ).reversal_axis().set_global_opts(
            title_opts=opts.TitleOpts(title='销售地Top10'),
            xaxis_opts=opts.AxisOpts(is_show=False),
            yaxis_opts=opts.AxisOpts(
                axistick_opts=opts.AxisTickOpts(is_show=False),
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(opacity=0)),
            ),
        ).render("销售地Top10.html"))
        print('生成完成')

        return c
def line_areastyle_boundary_gap() -> Line:
    c = (
        Line()
        .add_xaxis(["2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017"])
        .add_yaxis("70+ years old",七十岁以上, is_smooth=True)
        .add_yaxis("15-49 years old",十五至四十九岁, is_smooth=True)
        .add_yaxis("50-69 years old",五十至六十九岁, is_smooth=True)
        .set_series_opts(
            areastyle_opts=opts.AreaStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="按年龄划分的吸烟死亡人数"),
            xaxis_opts=opts.AxisOpts(
                axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
                is_scale=False,
                boundary_gap=False,
            ),
        )
    )
    return render_template('nl.html')
Example #29
0
def plot_line(dfs):
    x_data = dfs['品牌']
    y_data = dfs['Chg']
    line = Line().set_global_opts(
                    tooltip_opts=opts.TooltipOpts(is_show=False),
                    xaxis_opts=opts.AxisOpts(type_="category"),
                    yaxis_opts=opts.AxisOpts(
                                type_="value",
                                axistick_opts=opts.AxisTickOpts(is_show=True),
                                splitline_opts=opts.SplitLineOpts(is_show=True),
                            ),
                )\
                .add_xaxis(xaxis_data=x_data)\
                .add_yaxis(series_name="Chg",
                            y_axis=y_data,
                            symbol="emptyCircle",
                            is_symbol_show=True,
                            label_opts=opts.LabelOpts(is_show=False),)

    line.render("basic_line_chart.html")
    return line.render_embed()
Example #30
0
def drawPictorialBar(location, values, name):
    c = (
        PictorialBar().add_xaxis(location).add_yaxis(
            "",
            values,
            label_opts=opts.LabelOpts(is_show=False),
            symbol_size=22,
            symbol_repeat="fixed",
            symbol_offset=[0, -5],
            is_symbol_clip=True,
            # symbol='image://https://github.githubassets.com/images/spinners/octocat-spinner-32.gif'
            symbol='image://http://weizhendong.top/images/1.png').
        reversal_axis().set_global_opts(
            title_opts=opts.TitleOpts(title=name),
            xaxis_opts=opts.AxisOpts(is_show=False),
            yaxis_opts=opts.AxisOpts(
                axistick_opts=opts.AxisTickOpts(is_show=False),
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(opacity=0)),
            ),
        ).render("{0}.html".format(name)))