Esempio n. 1
0
from pyecharts import charts
from pyecharts import options as opts
value = 200
gu = charts.Gauge(init_opts=opts.InitOpts(width="640px", height="480px"))
gu.add(
    "指标",
    [("昨日单位面积能耗", value)],
    split_number=10,
    axisline_opts=opts.AxisLineOpts(
        linestyle_opts=opts.LineStyleOpts(color=[(
            0.2, "#00B050"), (0.4, "#67e0e3"), (0.7, "#FF6600"), (1,
                                                                  "#fd666d")],
                                          width=25)),
    min_=0,  # 最小刻度
    max_=1400,  # 最大刻度
)
gu.set_global_opts(
    title_opts=opts.TitleOpts(
        title="楼宇能耗指标表盘\n昨日单位面积能耗{0}Wh/m^2".format(value)),
    legend_opts=opts.LegendOpts(is_show=False),
)
gu.render(r"C:\Users\CQ375\Desktop\ex\Guage-eg.html")
Esempio n. 2
0
    f_y_data_6 = get_v(y_data_6)
    f_y_data_7 = get_v(y_data_7)
    f_y_data_8 = get_v(y_data_8)
    f_y_data_9 = get_v(y_data_9)
    f_y_data_10 = get_v(y_data_10)
    f_y_data_11 = get_v(y_data_11)
    f_y_data_12 = get_v(y_data_12)
    f_y_data_13 = get_v(y_data_13)
    f_y_data_14 = get_v(y_data_14)
    print(x_data)

    c = (
        Line().add_xaxis(xaxis_data=x_data).add_yaxis(
            "J1925",
            y_axis=f_y_data_1,
            linestyle_opts=opts.LineStyleOpts(width=1),
            label_opts=opts.LabelOpts(is_show=False),
            symbol_size=1).add_yaxis(
                "J2801",
                y_axis=f_y_data_2,
                linestyle_opts=opts.LineStyleOpts(width=1),
                label_opts=opts.LabelOpts(is_show=False),
                symbol_size=1).add_yaxis(
                    "J4568",
                    y_axis=f_y_data_3,
                    linestyle_opts=opts.LineStyleOpts(width=1),
                    label_opts=opts.LabelOpts(is_show=False),
                    symbol_size=1).add_yaxis(
                        "J4578",
                        y_axis=f_y_data_4,
                        linestyle_opts=opts.LineStyleOpts(width=1),
Esempio n. 3
0
        "2015-4",
        "2015-5",
        "2015-6",
        "2015-7",
        "2015-8",
        "2015-9",
        "2015-10",
        "2015-11",
        "2015-12",
    ],
    xaxis=opts.AxisOpts(
        type_="category",
        axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
        axisline_opts=opts.AxisLineOpts(
            is_on_zero=False,
            linestyle_opts=opts.LineStyleOpts(color="#6e9ef1")),
        axispointer_opts=opts.AxisPointerOpts(
            is_show=True,
            label=opts.LabelOpts(formatter=JsCode(js_formatter))),
    ),
).add_yaxis(
    series_name="2015 降水量",
    is_smooth=True,
    symbol="emptyCircle",
    is_symbol_show=False,
    # xaxis_index=1,
    color="#d14a61",
    y_axis=[
        2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3
    ],
    label_opts=opts.LabelOpts(is_show=False),
Esempio n. 4
0
    def kline(self):
        data = self.calculate().to_dict('list')
        kline = (
            Kline().add_xaxis(xaxis_data=data["date"]).add_yaxis(
                series_name="portfolio index",
                y_axis=data["datas"],
                itemstyle_opts=opts.ItemStyleOpts(
                    color="#ef232a",
                    color0="#14b143",
                    border_color="#ef232a",
                    border_color0="#14b143",
                ),
            ).set_global_opts(
                xaxis_opts=opts.AxisOpts(
                    type_="category",
                    is_scale=True,
                    boundary_gap=False,
                    axisline_opts=opts.AxisLineOpts(is_on_zero=False),
                    splitline_opts=opts.SplitLineOpts(is_show=False),
                    split_number=20,
                    min_="dataMin",
                    max_="dataMax",
                ),
                yaxis_opts=opts.AxisOpts(
                    is_scale=True,
                    splitline_opts=opts.SplitLineOpts(is_show=True)),
                datazoom_opts=[
                    opts.DataZoomOpts(is_show=False,
                                      type_="inside",
                                      xaxis_index=[0, 0],
                                      range_end=100),
                    opts.DataZoomOpts(is_show=True,
                                      xaxis_index=[0, 1],
                                      pos_top="97%",
                                      range_end=100),
                    opts.DataZoomOpts(is_show=False,
                                      xaxis_index=[0, 2],
                                      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"),
                ),
                brush_opts=opts.BrushOpts(
                    x_axis_index="all",
                    brush_link="all",
                    out_of_brush={"colorAlpha": 0.1},
                    brush_type="lineX",
                ),
                # 三个图的 axis 连在一块
                axispointer_opts=opts.AxisPointerOpts(
                    is_show=True,
                    link=[{
                        "xAxisIndex": "all"
                    }],
                    label=opts.LabelOpts(background_color="#777"),
                ),
            ))

        kline_line = (Line().add_xaxis(xaxis_data=data["date"]).add_yaxis(
            series_name="MA5",
            y_axis=self.calculate_ma(day_count=5, data=data),
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        ).add_yaxis(
            series_name="MA10",
            y_axis=self.calculate_ma(day_count=10, data=data),
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        ).add_yaxis(
            series_name="MA20",
            y_axis=self.calculate_ma(day_count=20, data=data),
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        ).add_yaxis(
            series_name="MA30",
            y_axis=self.calculate_ma(day_count=30, data=data),
            is_smooth=True,
            linestyle_opts=opts.LineStyleOpts(opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
        ).set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=1,
                axislabel_opts=opts.LabelOpts(is_show=False),
            ),
            yaxis_opts=opts.AxisOpts(
                grid_index=1,
                split_number=3,
                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=True),
            ),
        ))
        # Overlap Kline + Line
        overlap_kline_line = kline.overlap(kline_line)

        # Bar-1
        bar_1 = (Bar().add_xaxis(xaxis_data=data["date"]).add_yaxis(
            series_name="Volumn",
            y_axis=data["volume"],
            xaxis_index=1,
            yaxis_index=1,
            label_opts=opts.LabelOpts(is_show=False),
            itemstyle_opts=opts.ItemStyleOpts(color=JsCode("""
                    function(params) {
                        var colorList;
                        if (barData[params.dataIndex][1] > barData[params.dataIndex][0]) {
                            colorList = '#ef232a';
                        } else {
                            colorList = '#14b143';
                        }
                        return colorList;
                    }
                    """)),
        ).set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=1,
                axislabel_opts=opts.LabelOpts(is_show=False),
            ),
            legend_opts=opts.LegendOpts(is_show=False),
        ))

        # Bar-2 (Overlap Bar + Line)
        bar_2 = (Bar().add_xaxis(xaxis_data=data["date"]).add_yaxis(
            series_name="MACD",
            y_axis=data["MACD"],
            xaxis_index=2,
            yaxis_index=2,
            label_opts=opts.LabelOpts(is_show=False),
            itemstyle_opts=opts.ItemStyleOpts(color=JsCode("""
                            function(params) {
                                var colorList;
                                if (params.data >= 0) {
                                colorList = '#ef232a';
                                } else {
                                colorList = '#14b143';
                                }
                                return colorList;
                            }
                            """)),
        ).set_global_opts(
            xaxis_opts=opts.AxisOpts(
                type_="category",
                grid_index=2,
                axislabel_opts=opts.LabelOpts(is_show=False),
            ),
            yaxis_opts=opts.AxisOpts(
                grid_index=2,
                split_number=4,
                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=True),
            ),
            legend_opts=opts.LegendOpts(is_show=False),
        ))

        line_2 = (Line().add_xaxis(xaxis_data=data["date"]).add_yaxis(
            series_name="DIFF",
            y_axis=data["DIFF"],
            xaxis_index=2,
            yaxis_index=2,
            label_opts=opts.LabelOpts(is_show=False),
        ).add_yaxis(
            series_name="DEA",
            y_axis=data["DEA"],
            xaxis_index=2,
            yaxis_index=2,
            label_opts=opts.LabelOpts(is_show=False),
        ).set_global_opts(legend_opts=opts.LegendOpts(is_show=False)))
        # 最下面的柱状图和折线图
        overlap_bar_line = bar_2.overlap(line_2)

        # 最后的 Grid
        grid_chart = Grid(
            init_opts=opts.InitOpts(width="1500px", height="750px"))

        # 这个是为了把 data.datas 这个数据写入到 html 中,还没想到怎么跨 series 传值
        # demo 中的代码也是用全局变量传的
        grid_chart.add_js_funcs("var barData = {}".format(data["datas"]))

        # K线图和 MA5 的折线图
        grid_chart.add(
            overlap_kline_line,
            grid_opts=opts.GridOpts(pos_left="3%",
                                    pos_right="1%",
                                    height="60%"),
        )
        # Volumn 柱状图
        grid_chart.add(
            bar_1,
            grid_opts=opts.GridOpts(pos_left="3%",
                                    pos_right="1%",
                                    pos_top="71%",
                                    height="10%"),
        )
        # MACD DIFS DEAS
        grid_chart.add(
            overlap_bar_line,
            grid_opts=opts.GridOpts(pos_left="3%",
                                    pos_right="1%",
                                    pos_top="82%",
                                    height="14%"),
        )
        makedir(self.path, 'kline')
        grid_chart.render(
            f"{self.path}\\kline\\{str(self.names)}_{time.strftime('%Y-%m-%d', time.localtime())}.html"
        )
Esempio n. 5
0
def line_time_genera():
    '''
    根据三部电影影评的时间分布,
    绘制折线区域图;
    :return:
    '''
    csv_path = 'C:/Users/FREEDOM/Desktop/{}.csv'.format('pandeng')
    csv_path1 = 'C:/Users/FREEDOM/Desktop/{}.csv'.format('zuguo')
    csv_path2 = 'C:/Users/FREEDOM/Desktop/{}.csv'.format('jizhang')

    data_csv = pd.read_csv(csv_path, encoding='gbk')
    data_csv1 = pd.read_csv(csv_path1, encoding='gbk')
    data_csv2 = pd.read_csv(csv_path2, encoding='gbk')

    time_list = []
    time_list1 = []
    time_list2 = []
    '''
    数据处理,时间处理为0:00-01:00的格式;
    '''
    for i, j, k in zip(data_csv['time'], data_csv1['time'], data_csv2['time']):
        new_i = str(i).split(' ')[1].split(':')[0]
        new_i1 = '{}:00-{}.00'.format(new_i, int(new_i) + 1)
        new_j = str(j).split(' ')[1].split(':')[0]
        new_j1 = '{}:00-{}.00'.format(new_j, int(new_j) + 1)
        new_k1 = str(k).split(' ')[1].split(':')[0]
        time_list.append(new_i1)
        time_list1.append(new_j1)
        time_list2.append(new_k1)

    dict = {}
    dict1 = {}
    dict2 = {}

    a_list = []
    a_list.extend(sorted(set(time_list2))[:1])
    a_list.extend(sorted(set(time_list2))[-11:-10])
    a_list.extend(sorted(set(time_list2))[-6:])
    a_list.extend(sorted(set(time_list2))[1:-11])

    for j in a_list:
        '''
        若在列表中j存在,则就把j的数量匹配上去,
        否则直接设为0;
        '''
        if j in time_list:
            count = time_list.count(j)
            dict[j] = count
        else:
            dict[j] = 0

        if j in time_list1:
            count1 = time_list1.count(j)
            dict1[j] = count1
        else:
            dict1[j] = 0

        if j in time_list2:
            count2 = time_list2.count(j)
            dict2[j] = count2
        else:
            dict2[j] = 0

    c = (Line().add_xaxis(xaxis_data=[i for i in dict.keys()]).add_yaxis(
        "《我和我的祖国》",
        y_axis=[j for j in dict1.values()],
        linestyle_opts=opts.LineStyleOpts(width=2),
    ).add_yaxis(
        "《攀登者》",
        y_axis=[j for j in dict.values()],
        linestyle_opts=opts.LineStyleOpts(width=2),
    ).add_yaxis(
        "《中国机长》",
        y_axis=[j for j in dict2.values()],
        linestyle_opts=opts.LineStyleOpts(width=2),
    ).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="豆瓣暑假档影评时间分布",
                                  subtitle='数据来源:www.douban.com'),
        xaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_align_with_label=True),
            is_scale=False,
            boundary_gap=False,
        ),
    ))
    #生成html网页;
    c.render('line.html')
Esempio n. 6
0
def chart():
    kline=(
        Kline()
        .add_xaxis(stock_date)
        .add_yaxis("Kline", stock_price)
        .set_global_opts(
            xaxis_opts=opts.AxisOpts(is_scale=True),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                # 顯示分割
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
                ),
            ),

            # 圖例位置
            legend_opts=opts.LegendOpts(is_show=True, pos_top=10, pos_left="center"),
            # DataZoom slider
            datazoom_opts=[opts.DataZoomOpts(is_show=False, type_="inside",
                                             xaxis_index=[0, 1], range_start=0, range_end=100, ),
                           opts.DataZoomOpts(is_show=True, xaxis_index=[0, 1], type_="slider",
                                             pos_top="90%", range_start=0, 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")
            ),

            # axispointer_opts.AxisPointerOpts(is_show=True,link=[{"xAxisIndex":"all"}],
            # label=opts.LabelOpts(background_color=''#777'),),

            # 區域選擇組件
            # brush_opts=opts.BrushOpts(#指定所有數列對應的座標系x_axis_index="all",#指定哪些 series
            # 可以被聯動brush_link="all",#定義顏色透明度out_of_brush={"colorAlpha":0.1},brush_type="lineX",),

        )
    )

    line=(
        Line()
        .add_xaxis(stock_date)
        .add_yaxis("10日移動平均線", sma_10, is_smooth=True,
                    label_opts=opts.LabelOpts(is_show=False),
                    linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5))
        .add_yaxis("120日移動平均線", sma_120, is_smooth=True,
                    label_opts=opts.LabelOpts(is_show=False),
                    linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5))
        .add_yaxis("240日移動平均線", sma_240, is_smooth=True,
                    label_opts=opts.LabelOpts(is_show=False),
                    linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5))
        .set_global_opts(
            xaxis_opts=opts.AxisOpts(type_="category"),
        )
    )

    bar = (
        Bar()
            .add_xaxis(stock_date)
            .add_yaxis("交易量", stock_volume_red, gap="0%",
                       xaxis_index=1, yaxis_index=1, label_opts=opts.LabelOpts(is_show=False),
                       itemstyle_opts=opts.ItemStyleOpts(color="#A73835"),
                       )
            .add_yaxis("交易量", stock_volume_green,gap="0%",
                       xaxis_index=1, yaxis_index=1, label_opts=opts.LabelOpts(is_show=False),
                       itemstyle_opts=opts.ItemStyleOpts(color="#424A56"),
                       )
            .add_yaxis("交易量", stock_volume_gray,gap="0%",
                       xaxis_index=1, yaxis_index=1, label_opts=opts.LabelOpts(is_show=False),
                       itemstyle_opts=opts.ItemStyleOpts(color="#404143")
                       )
            .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, ),
            yaxis_opts=opts.AxisOpts(grid_index=1, is_scale=True, split_number=2,
                                     axislabel_opts=opts.LabelOpts(is_show=False),
                                     axisline_opts=opts.AxisLineOpts(is_show=False),
                                     axistick_opts=opts.AxisTickOpts(is_show=False),
                                     ),

            legend_opts=opts.LegendOpts(is_show=False),

        )
    )


    overlap_kline_line = kline.overlap(line)

    global grid_chart

    grid_chart = (
        Grid()
        .add(overlap_kline_line,
             grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", height="50%"),
             )
        .add(bar,
             grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", pos_top="70%", height="16%"), )
    )

    grid_chart.render()
Esempio n. 7
0
def Pycharts():
    with open('reviews/pos.txt', "r") as f:  # 训练集可持续化,读取上次写文件名,这次接着来
        total_reviews_ups = f.read()
    if total_reviews_ups == '':
        print('请爬取训练集')
    else:
        total_reviews_up = int(total_reviews_ups)
    with open('reviews/neg.txt', "r") as f:  # 训练集可持续化
        total_reviews_downs = f.read()
    if total_reviews_downs == '':
        print('请爬取训练集')
    else:
        total_reviews_down = int(total_reviews_downs)


    file = open('reviews_over.txt', 'r', encoding='UTF-8')  # 路径自定义
    text = file.read()
    file.close()
    cut_text = " ".join(jieba.cut(text))
    words = cut_text.split()
    words1 = [re.sub("[\,\。\!\;\?\、\”\“]", '', word) for word in words]  # 去掉标点符号
    #停用词 自定义词典
    jieba.load_userdict("dict.txt")
    stopwords_file = "stopwords.txt"
    stop_f = open(stopwords_file, "r", encoding='utf-8')
    stop_words = list()
    for line in stop_f.readlines():
        line = line.strip()
        if not len(line):
            continue
        stop_words.append(line)
    stop_f.close
    DIY_stopwords = ['一个','没有','说','玩','做','里','中','-','⣿','','感','spoiler','2','点','完','·','\\','4','走','一款',"'",'会','没',',','游戏','帧','/']
    for line in range(0,len(DIY_stopwords)):
        stop_words.append(DIY_stopwords[line])
    words2 = [word for word in words1 if word not in stop_words] #停用词
    wordcounts = collections.Counter(words2).most_common(200)
    #print(wordcounts)

    #词云
    cloud = (
        WordCloud(opts.InitOpts(width="100%", height="950px"))
            .add("词频统计", wordcounts, word_size_range=[20, 300], )
            .set_global_opts(
            title_opts=opts.TitleOpts(
                title="词频统计", title_textstyle_opts=opts.TextStyleOpts(font_size=23)
            ),
            tooltip_opts=opts.TooltipOpts(is_show=True),
            )
            .render("html/wordcloud_diamond.html")
    )

    UP = (
        Gauge(init_opts=opts.InitOpts(width="500px", height="500px"))
            .add(series_name="推荐指数", data_pair=[["", sa.pos/(sa.pos+sa.neg)*100]],
                 title_label_opts=opts.LabelOpts(font_size=40, color="blue", font_family="Microsoft YaHei"),
                 )
            .set_global_opts(
            legend_opts=opts.LegendOpts(is_show=False),
            tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"),
        )
            .set_series_opts(axisline_opts=opts.AxisLineOpts(
            linestyle_opts=opts.LineStyleOpts(color=[[0.3, "#67e0e3"], [0.7, "#37a2da"], [1, "#fd666d"]], width=30)
        )
        )
            .render("html/gauge_up.html")
    )

    DOWN = (
        Gauge(init_opts=opts.InitOpts(width="500px", height="500px"))
            .add(series_name="推荐指数", data_pair=[["", sa.neg/(sa.pos+sa.neg)*100]],
                 title_label_opts=opts.LabelOpts(font_size=40, color="blue", font_family="Microsoft YaHei"),
                 )
            .set_global_opts(
            legend_opts=opts.LegendOpts(is_show=False),
            tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{a} <br/>{b} : {c}%"),
        )
            .set_series_opts(axisline_opts=opts.AxisLineOpts(
            linestyle_opts=opts.LineStyleOpts(color=[[0.3, "#67e0e3"], [0.7, "#37a2da"], [1, "#fd666d"]], width=30)
            )
                             )
            .render("html/gauge_down.html")
    )

    pie = (
        Pie()
            .add(
            "1",
            [['正面训练集数量',total_reviews_up ], ['负面训练集数量', total_reviews_down]],
            radius=["40%", "75%"],
            )
            .set_global_opts(
            title_opts=opts.TitleOpts(title="Pie-Radius"),
            legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%"),
            )
            .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
            .render("html/pie.html")
    )

    bar = (
        Bar()
            .add_xaxis(['推荐', '不推荐'])
            .add_yaxis("识别成功", [pospic,negpic], stack="stack1")
            .add_yaxis("识别失败", [totpos-pospic,totneg-negpic], stack="stack1")
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
            .set_global_opts(title_opts=opts.TitleOpts(title="准确度为%s" %str(RecommendCent)))
            .render("html/bar.html")
    )

    webbrowser.open('file:///F:/Project/WorkSpace/2077CommentAnalyze/Python/html/index.html')
Esempio n. 8
0
def draw_chart(ts_code, start_date, end_date):
    '''
        pyecharts V1 版本开始支持链式调用
       文档地址 https://pyecharts.org/#/zh-cn/
    '''
    stock_data = get_process_datas(ts_code, start_date, end_date)
    stock_data.index = pd.to_datetime(stock_data['TIME'], format="%Y/%m/%d")
    x = stock_data["TIME"].values.tolist()
    stock_basic_data = stock_data[[
        "TIME", "OPEN", "CLOSE", "LOW", "HIGH", "VOLUME"
    ]]
    # stock_data = stock_data.sort_index(ascending=True)  # 倒序,看时间顺序是否正常决定是不是要用
    # k线图
    kline = (
        Kline().add_xaxis(x).add_yaxis(
            "K线图",
            stock_basic_data.iloc[:, 1:5].values.tolist(),
            itemstyle_opts=opts.ItemStyleOpts(color="#ec0000",
                                              color0="#00da3c"),
        ).set_global_opts(
            xaxis_opts=opts.AxisOpts(is_scale=True, is_show=False),
            # axis_opts=opts.AxisOpts(is_scale=True,min_=0), #y轴起始坐标可以设为0
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),  # y轴起始坐标可自动调整
            tooltip_opts=opts.TooltipOpts(trigger="axis",
                                          axis_pointer_type="line"),
            legend_opts=opts.LegendOpts(is_show=True,
                                        orient='vertical',
                                        pos_right="5%",
                                        pos_top='20%'),
            title_opts=opts.TitleOpts(title="股票价格",
                                      subtitle=ts_code,
                                      pos_left='22%',
                                      pos_top="20%"),
            #把所有的x轴连接在一起
            # axispointer_opts=opts.AxisPointerOpts(is_show=True,
            #                                       link=[{"xAxisIndex": "all"}],
            #                                       label=opts.LabelOpts(background_color="#777"),
            #                                       ),
            datazoom_opts=[  # 设置zoom参数后即可缩放
                opts.DataZoomOpts(
                    is_show=True,
                    type_="inside",
                    xaxis_index=[0, 1, 2, 3, 4],  # 设置第0轴和第1轴同时缩放
                    range_start=0,
                    range_end=100,
                ),
            ],
        ))
    # 成交量柱形图
    bar_volumn = (Bar().add_xaxis(x).add_yaxis(
        "成交量",
        stock_basic_data["VOLUME"].values.tolist(),
        xaxis_index=1,
        yaxis_index=1,
        label_opts=opts.LabelOpts(is_show=False),
        itemstyle_opts=opts.ItemStyleOpts(color=JsCode("""
                           function(params) {
                               var colorList;
                               if (barData[params.dataIndex][1] > barData[params.dataIndex][0]) {
                                   colorList = '#ef232a';

                               } else {
                                   colorList = '#14b143';
                               }
                               return colorList;
                           }
                           """)),
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="成交量", pos_left='22%', pos_top="48%"),
        legend_opts=opts.LegendOpts(is_show=True,
                                    orient='vertical',
                                    pos_right="5%",
                                    pos_top='48%'),
    ))
    #绘制均线图
    line_ma = (
        Line().add_xaxis(x).add_yaxis(
            series_name="MA5",
            y_axis=stock_data["MA5"].values.tolist(),
            is_hover_animation=False,
            # linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
            label_opts=opts.LabelOpts(is_show=False),
            is_symbol_show=False,
        ).add_yaxis(
            series_name="MA10",
            y_axis=stock_data["MA10"].values.tolist(),
            is_hover_animation=False,
            label_opts=opts.LabelOpts(is_show=False),
            is_symbol_show=False,
        ).add_yaxis(
            series_name="MA20",
            y_axis=stock_data["MA20"].values.tolist(),
            is_hover_animation=False,
            label_opts=opts.LabelOpts(is_show=False),
            is_symbol_show=False,
        ).set_global_opts(
            title_opts=opts.TitleOpts(title="MA",
                                      pos_left='22%',
                                      pos_top="88%"),
            xaxis_opts=opts.AxisOpts(
                type_="category",
                axislabel_opts=opts.LabelOpts(is_show=False),
                is_scale=True),
            datazoom_opts=[opts.DataZoomOpts(type_="inside")],
            legend_opts=opts.LegendOpts(is_show=True,
                                        orient='vertical',
                                        pos_right="5%",
                                        pos_top='85%'),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),
        ))
    #绘制jdk线
    line_kdj = (Line().add_xaxis(x).add_yaxis(
        series_name="K",
        y_axis=stock_data["K"].values.tolist(),
        linestyle_opts=opts.LineStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).add_yaxis(
        series_name="D",
        y_axis=stock_data["D"].values.tolist(),
        linestyle_opts=opts.LineStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).add_yaxis(
        series_name="J",
        y_axis=stock_data["J"].values.tolist(),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="KDJ", pos_left='22%', pos_top="62%"),
        datazoom_opts=[opts.DataZoomOpts(type_="inside", )],
        legend_opts=opts.LegendOpts(is_show=True,
                                    orient='vertical',
                                    pos_right="7%",
                                    pos_top='60%'),
        xaxis_opts=opts.AxisOpts(
            is_scale=True,
            axislabel_opts=opts.LabelOpts(is_show=False),
        ),
        yaxis_opts=opts.AxisOpts(
            is_scale=True,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        ),
    ))
    #绘制macd柱状图
    bar_macd = (Bar().add_xaxis(x).add_yaxis(
        series_name='MACD',
        yaxis_data=stock_data['MACD'].values.tolist(),
        xaxis_index=2,
        yaxis_index=2,
        label_opts=opts.LabelOpts(is_show=False),
        itemstyle_opts=opts.ItemStyleOpts(color=JsCode("""
                               function(params) {
                                   var colorList;
                                   if (params.data >= 0) {
                                     colorList = '#ef232a';
                                   } else {
                                     colorList = '#14b143';
                                   }
                                   return colorList;
                               }
                               """)),
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="MACD", pos_left='22%', pos_top="75%"),
        xaxis_opts=opts.AxisOpts(
            type_="category",
            grid_index=2,
            axislabel_opts=opts.LabelOpts(is_show=False),
        ),
        yaxis_opts=opts.AxisOpts(
            grid_index=2,
            split_number=4,
            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=True),
        ),
        legend_opts=opts.LegendOpts(is_show=True,
                                    orient='vertical',
                                    pos_right="5%",
                                    pos_top='70%'),
    ))
    #绘制DIF和DEA
    line_macd = (Line().add_xaxis(x).add_yaxis(
        series_name="DIF",
        y_axis=stock_data['DIF'].values.tolist(),
        xaxis_index=2,
        yaxis_index=2,
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).add_yaxis(
        series_name="DEA",
        y_axis=stock_data['DEA'].values.tolist(),
        xaxis_index=2,
        yaxis_index=2,
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).set_global_opts(legend_opts=opts.LegendOpts(is_show=False)))
    #绘制布林线
    line_boll = (Line().add_xaxis(x).add_yaxis(
        series_name="MID",
        y_axis=stock_data["MID"].values.tolist(),
        linestyle_opts=opts.LineStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).add_yaxis(
        series_name="UPPER",
        y_axis=stock_data["UPPER"].values.tolist(),
        linestyle_opts=opts.LineStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).add_yaxis(
        series_name="LOWER",
        y_axis=stock_data["LOWER"].values.tolist(),
        linestyle_opts=opts.LineStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).set_global_opts(
        datazoom_opts=[opts.DataZoomOpts(type_="inside", )],
        xaxis_opts=opts.AxisOpts(is_scale=True),
        yaxis_opts=opts.AxisOpts(
            is_scale=True,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        ),
    ))

    overlap_kline_linema = kline.overlap(line_boll)
    overlap_macd = bar_macd.overlap(line_macd)
    # 使用网格将多张图标组合到一起显示
    grid_chart = Grid(init_opts=opts.InitOpts(
        width="1400px",
        height="700px",
        animation_opts=opts.AnimationOpts(animation=False),
    ))

    # 为了把 data.datas 的数据写入到html中作为全局变量,目前无法跨 series 传值
    # demo 中的代码也是用全局变量传的
    grid_chart.add_js_funcs("var barData = {}".format(
        stock_basic_data.iloc[:, 1:5].values.tolist()))
    grid_chart.add(
        overlap_kline_linema,
        grid_opts=opts.GridOpts(pos_left="35%",
                                pos_right="15%",
                                pos_top="3%",
                                height="40%"),
    )

    grid_chart.add(
        bar_volumn,
        grid_opts=opts.GridOpts(pos_left="35%",
                                pos_right="15%",
                                pos_top="45%",
                                height="10%"),
    )

    grid_chart.add(line_kdj,
                   grid_opts=opts.GridOpts(pos_left="35%",
                                           pos_right="15%",
                                           pos_top="60%",
                                           height="10%"))
    grid_chart.add(overlap_macd,
                   grid_opts=opts.GridOpts(pos_left="35%",
                                           pos_right="15%",
                                           pos_top="72%",
                                           height="10%"))

    grid_chart.add(line_ma,
                   grid_opts=opts.GridOpts(pos_left="35%",
                                           pos_right="15%",
                                           pos_top="85%",
                                           height="10%"))

    grid_chart.render('stock_{}/stock_{}.html'.format(
        ts_code, ts_code))  # 保存成用股票代码命名的文档
    return 0
Esempio n. 9
0
               itemstyle_opts=opts.ItemStyleOpts(border_color="#111",
                                                 color='#454545'))
# 添加系列
geo.add(
    '',
    [('成都', 10), ('武汉', 20), ('西安', 30), ('南京', 40), ('深圳', 50)],
    type_=ChartType.EFFECT_SCATTER,  # 散点图一种形式
    label_opts=opts.LabelOpts(is_show=True),  # 不显示设置False
)
geo.add(
    '',
    [('北京', 100), ('上海', 100)],
    type_=ChartType.HEATMAP,  # 散点图的一种形式
    label_opts=opts.LabelOpts(is_show=False),
)

# 设置流向
geo.add(
    '流向图',
    [('上海', '成都'), ('上海', '南京'), ('上海', '深圳'), ('上海', '武汉'), ('北京', '西安'),
     ('北京', '成都'), ('北京', '南京'), ('北京', '武汉')],
    type_=ChartType.LINES,
    linestyle_opts=opts.LineStyleOpts(curve=0.3, color="#63B8FF"),
    effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,
                                symbol_size=6,
                                color='#FF7F00'),
)

# 生成图片
geo.render('./data/geo_liuxiang.html')
Esempio n. 10
0
def grid_mutil_yaxis() -> Grid:
    x_data = ["{}月".format(i) for i in range(1, 13)]
    bar = (
        Bar()
        .add_xaxis(x_data)
        .add_yaxis(
            "蒸发量",
            [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
            yaxis_index=0,
            color="#d14a61",
        )
        .add_yaxis(
            "降水量",
            [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
            yaxis_index=1,
            color="#5793f3",
        )
        .extend_axis(
            yaxis=opts.AxisOpts(
                name="蒸发量",
                type_="value",
                min_=0,
                max_=250,
                position="right",
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(color="#d14a61")
                ),
                axislabel_opts=opts.LabelOpts(formatter="{value} ml"),
            )
        )
        .extend_axis(
            yaxis=opts.AxisOpts(
                type_="value",
                name="温度",
                min_=0,
                max_=25,
                position="left",
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(color="#675bba")
                ),
                axislabel_opts=opts.LabelOpts(formatter="{value} °C"),
                splitline_opts=opts.SplitLineOpts(
                    is_show=True, linestyle_opts=opts.LineStyleOpts(opacity=1)
                ),
            )
        )
        .set_global_opts(
            yaxis_opts=opts.AxisOpts(
                name="降水量",
                min_=0,
                max_=250,
                position="right",
                offset=80,
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(color="#5793f3")
                ),
                axislabel_opts=opts.LabelOpts(formatter="{value} ml"),
            ),
            title_opts=opts.TitleOpts(title="Grid-多 Y 轴示例"),
            tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
        )
    )

    line = (
        Line()
        .add_xaxis(x_data)
        .add_yaxis(
            "平均温度",
            [3.3, 10.2, 20.3, 23.0, 16.5],
            yaxis_index=2,
            color="#675bba",
            label_opts=opts.LabelOpts(is_show=False),
        )
    )

    bar.overlap(line)
    return Grid().add(bar, opts.GridOpts(pos_left="5%", pos_right="20%"), is_control_axis_index=True)
Esempio n. 11
0
def draw_peak_charts(ts_code, start_date, end_date, name):
    stock_data = get_process_datas(ts_code, start_date, end_date)
    x = stock_data['TIME'].values.tolist()
    y = stock_data[name].values.tolist()
    indexes_peaks, line_peaks = get_line_peaks(stock_data[name])
    indexes_valleys, line_valleys = get_line_valleys(stock_data[name])

    line = (
        Line().add_xaxis(x).add_yaxis(
            '收盘价',
            y,
            label_opts=opts.LabelOpts(is_show=False),
            is_symbol_show=False,
        ).set_global_opts(
            xaxis_opts=opts.AxisOpts(is_scale=True),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),
            datazoom_opts=[opts.DataZoomOpts(type_="inside")],
            title_opts=opts.TitleOpts(title="股票价格",
                                      subtitle=ts_code,
                                      pos_left='15%',
                                      pos_top="40%"),
            # 把所有的x轴连接在一起
            axispointer_opts=opts.AxisPointerOpts(
                is_show=True,
                link=[{
                    "xAxisIndex": "all"
                }],
                label=opts.LabelOpts(background_color="#777"),
            ),
        ))

    # 极大值的散点图
    scatter_peak = (Scatter().add_xaxis(indexes_peaks).add_yaxis(
        'Peaks',
        line_peaks,
        label_opts=opts.LabelOpts(is_show=False),
        symbol='triangle',
        symbol_rotate=180,
        itemstyle_opts=opts.ItemStyleOpts(color='#ef232a')).set_global_opts(
            xaxis_opts=opts.AxisOpts(is_scale=True),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),
            datazoom_opts=[opts.DataZoomOpts(type_="inside")],
        ))

    scatter_valley = (Scatter().add_xaxis(indexes_valleys).add_yaxis(
        'Valleys',
        line_valleys,
        label_opts=opts.LabelOpts(is_show=False),
        symbol='triangle',
        itemstyle_opts=opts.ItemStyleOpts(color='#14b143')).set_global_opts(
            xaxis_opts=opts.AxisOpts(is_scale=True),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),
            datazoom_opts=[opts.DataZoomOpts(type_="inside")],
        ))
    #绘制布林带
    line_boll = (Line().add_xaxis(x).add_yaxis(
        series_name="MID",
        y_axis=stock_data["MID"].values.tolist(),
        linestyle_opts=opts.LineStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).add_yaxis(
        series_name="UPPER",
        y_axis=stock_data["UPPER"].values.tolist(),
        linestyle_opts=opts.LineStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).add_yaxis(
        series_name="LOWER",
        y_axis=stock_data["LOWER"].values.tolist(),
        linestyle_opts=opts.LineStyleOpts(opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).set_global_opts(
        datazoom_opts=[opts.DataZoomOpts(type_="inside", )],
        xaxis_opts=opts.AxisOpts(is_scale=True),
        yaxis_opts=opts.AxisOpts(
            is_scale=True,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        ),
    ))

    stock_basic_data = stock_data[["TIME", "OPEN", "CLOSE", "LOW", "HIGH"]]
    # 绘制K线图
    kline = (
        Kline().add_xaxis(x).add_yaxis(
            "K线图",
            stock_basic_data.iloc[:, 1:5].values.tolist(),
            itemstyle_opts=opts.ItemStyleOpts(color="#ec0000",
                                              color0="#00da3c"),
        ).set_global_opts(
            xaxis_opts=opts.AxisOpts(is_scale=True, is_show=False),
            # axis_opts=opts.AxisOpts(is_scale=True,min_=0), #y轴起始坐标可以设为0
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),  # y轴起始坐标可自动调整
            tooltip_opts=opts.TooltipOpts(trigger="axis",
                                          axis_pointer_type="line"),
            legend_opts=opts.LegendOpts(is_show=True,
                                        orient='vertical',
                                        pos_right="5%",
                                        pos_top='20%'),
            datazoom_opts=[  # 设置zoom参数后即可缩放
                opts.DataZoomOpts(
                    is_show=True,
                    type_="inside",
                ),
            ],
        ))
    line_close = (Line().add_xaxis(x).add_yaxis(
        '五日均线',
        stock_data["MA5"].values.tolist(),
        label_opts=opts.LabelOpts(is_show=False),
        is_symbol_show=False,
    ).set_global_opts(
        xaxis_opts=opts.AxisOpts(is_scale=True),
        yaxis_opts=opts.AxisOpts(
            is_scale=True,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        ),
        datazoom_opts=[opts.DataZoomOpts(type_="inside")],
    ))
    overlap_findpeak = line.overlap(scatter_peak)
    overlap_findpeak = overlap_findpeak.overlap(scatter_valley)
    overlap_findpeak = overlap_findpeak.overlap(line_boll)
    overlap_findpeak = overlap_findpeak.overlap(kline)
    overlap_findpeak = overlap_findpeak.overlap(line_close)

    grid_chart = Grid(init_opts=opts.InitOpts(
        width="1400px",
        height="700px",
        animation_opts=opts.AnimationOpts(animation=False),
    ))

    grid_chart.add(
        overlap_findpeak,
        grid_opts=opts.GridOpts(pos_left="25%", pos_right="15%",
                                pos_top="10%"),
    )

    grid_chart.render('stock_{}/find_peak.html'.format(ts_code))
Esempio n. 12
0
1、暂无
"""

x_data = ["一", "二", "三", "四", "五", "六", "七", "八", "九"]
y_data_3 = [1, 3, 9, 27, 81, 247, 741, 2223, 6669]
y_data_2 = [1, 2, 4, 8, 16, 32, 64, 128, 256]
y_data_05 = [1 / 2, 1 / 4, 1 / 8, 1 / 16, 1 / 32, 1 / 64, 1 / 128, 1 / 256, 1 / 512]


(
    Line(init_opts=opts.InitOpts(width="1600px", height="800px"))
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="1/2的指数",
        y_axis=y_data_05,
        linestyle_opts=opts.LineStyleOpts(width=2),
    )
    .add_yaxis(
        series_name="2的指数", y_axis=y_data_2, linestyle_opts=opts.LineStyleOpts(width=2)
    )
    .add_yaxis(
        series_name="3的指数", y_axis=y_data_3, linestyle_opts=opts.LineStyleOpts(width=2)
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="对数轴示例", pos_left="center"),
        tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{a} <br/>{b} : {c}"),
        legend_opts=opts.LegendOpts(pos_left="left"),
        xaxis_opts=opts.AxisOpts(type_="category", name="x"),
        yaxis_opts=opts.AxisOpts(
            type_="log",
            name="y",
Esempio n. 13
0
from pyecharts.faker import Faker

tl = Timeline()
names = ("商家A", "商家B", "商家C")
nodes = [{"name": name} for name in names]
for i in range(2015, 2020):
    links = [
        {
            "source": names[0],
            "target": names[1],
            "value": Faker.values()[0]
        },
        {
            "source": names[1],
            "target": names[2],
            "value": Faker.values()[0]
        },
    ]
    sankey = (Sankey().add(
        "sankey",
        nodes,
        links,
        linestyle_opt=opts.LineStyleOpts(opacity=0.2,
                                         curve=0.5,
                                         color="source"),
        label_opts=opts.LabelOpts(position="right"),
    ).set_global_opts(title_opts=opts.TitleOpts(
        title="{}年商店(A, B, C)营业额差".format(i))))
    tl.add(sankey, "{}年".format(i))
put_html(tl.render_notebook())
Esempio n. 14
0
from pyecharts import options as opts
from pyecharts.charts import PictorialBar
from pyecharts.globals import SymbolType

location = ["山西", "四川", "西藏", "北京", "上海", "内蒙古", "云南", "黑龙江", "广东", "福建"]
values = [13, 42, 67, 81, 86, 94, 166, 220, 249, 262]

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)),
    ),
).render("Pictorialbar_base.html"))
area_color_js = (
    "new echarts.graphic.LinearGradient(0, 0, 0, 1, "
    "[{offset: 0, color: '#eb64fb'}, {offset: 1, color: '#3fbbff0d'}], false)"
)

c = (
    Line(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js)))
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="注册总量",
        y_axis=y_data,
        is_smooth=True,
        is_symbol_show=True,
        symbol="circle",
        symbol_size=6,
        linestyle_opts=opts.LineStyleOpts(color="#fff"),
        label_opts=opts.LabelOpts(is_show=True, position="top", color="white"),
        itemstyle_opts=opts.ItemStyleOpts(
            color="red", border_color="#fff", border_width=3
        ),
        tooltip_opts=opts.TooltipOpts(is_show=False),
        areastyle_opts=opts.AreaStyleOpts(color=JsCode(area_color_js), opacity=1),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(
            title="OCTOBER 2015",
            pos_bottom="5%",
            pos_left="center",
            title_textstyle_opts=opts.TextStyleOpts(color="#fff", font_size=16),
        ),
        xaxis_opts=opts.AxisOpts(
Esempio n. 16
0
 schema=[
     opts.RadarIndicatorItem(name="灵活性", max_=100,color='#98F5FF'),
     opts.RadarIndicatorItem(name="功能性", max_=100,color='#98F5FF'),
     opts.RadarIndicatorItem(name="平稳性", max_=100,color='#98F5FF'),
     opts.RadarIndicatorItem(name="安全性", max_=100,color='#98F5FF'),
     opts.RadarIndicatorItem(name="耐用性", max_=100,color='#98F5FF'),
 ],
 center=['50%', '50%'],
 textstyle_opts=opts.TextStyleOpts(
     color='red',
 ),
 splitline_opt=opts.SplitLineOpts(
         is_show= True,
         linestyle_opts=opts.LineStyleOpts(
             color='#98F5FF',
             width=1,
             type_='dotted'
         )
     ),
 axisline_opt=opts.AxisLineOpts(
         linestyle_opts=opts.AxisLineOpts(
             linestyle_opts=opts.LineStyleOpts(
             color='#98F5FF',
             )
         )
     ),
 splitarea_opt=opts.SplitAreaOpts(
     is_show=True,
     areastyle_opts=opts.AreaStyleOpts(
         color=['#141c42', '#141c42']
     )
Esempio n. 17
0
def draw_chart(df):
    # temp = df[df['signal'].notnull()][['signal']]
    # temp = temp[temp['signal'] != temp['signal'].shift(1)]
    signal = df[df['signal'] == 1].values.tolist()
    high = df['high'].values.tolist()
    date = df['candle_begin_time'].values.tolist()

    new_data = df[['open', 'close', 'high', 'low']].values.tolist()
    line_upper_data = list(df['line_upper'].values)
    line_median_data = list(df['line_median'].values)
    line_lower_data = list(df['line_lower'].values)

    es = (
        EffectScatter()
        .add_xaxis(date)
        .add_yaxis("", signal)
    )

    kline = (
        Kline()
            .add_xaxis(xaxis_data=date)
            .add_yaxis("k_线图",
                       y_axis=new_data,
                       itemstyle_opts=opts.ItemStyleOpts(color="#ec0000",color0="#00da3c",border_color="#8A0000",border_color0="#008F28",),
                       markpoint_opts=opts.MarkPointOpts(
                           data=[
                               opts.MarkPointItem(type_="signal", name="signal")
                           ]
                       ),)
            .set_global_opts(
            xaxis_opts=opts.AxisOpts(is_scale=True),
            yaxis_opts=opts.AxisOpts(
                is_scale=True,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
                ),
            ),
            datazoom_opts=[opts.DataZoomOpts(type_="inside")],
        )

    )

    overlap_kline = kline.overlap(es)

    kline_line = (
        Line()
        .add_xaxis(xaxis_data=date)
            .add_yaxis(
            series_name="upper",
            y_axis=line_upper_data,
            is_smooth=True,
            is_hover_animation=False,
            linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
            itemstyle_opts=opts.ItemStyleOpts(color="#0004a1"),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .add_yaxis(
            series_name="median",
            y_axis=line_median_data,
            is_smooth=True,
            is_hover_animation=False,
            linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
            itemstyle_opts=opts.ItemStyleOpts(color="#fff401"),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .add_yaxis(
            series_name="lower",
            y_axis=line_lower_data,
            is_smooth=True,
            is_hover_animation=False,
            linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
            itemstyle_opts=opts.ItemStyleOpts(color="#71f401"),
            label_opts=opts.LabelOpts(is_show=False),
        )
        .set_global_opts(xaxis_opts=opts.AxisOpts(type_="category"))
    )

    overlap_kline_line = kline_line.overlap(overlap_kline)

    # Kline And Line
    # overlap_kline_line = kline.overlap(line)
    # overlap_kline_line.render_notebook()
    # grid_chart = Grid(init_opts=opts.InitOpts(width="1400px", height="800px"))
    # grid_chart.add(
    #     overlap_kline_line,
    #     # 设置位置
    #     grid_opts=opts.GridOpts(pos_left="3%", pos_right="1%", pos_top="2%", height="80%"),
    # )
    overlap_kline.render()
Esempio n. 18
0
                       value=2))

# %%

c = (
    Graph(init_opts=opts.InitOpts(
        width="100%",  # 图宽
        height="700px",  # 图高
        renderer=
        "canvas",  # 渲染模式 svg 或 canvas,即 RenderType.CANVAS 或 RenderType.SVG
    )).add(
        "",
        nodes_data,
        links_data,
        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=False),
        title_opts=opts.TitleOpts(
            title="Graph-GraphNode-GraphLink-WithEdgeLabel"),
    ).render("graph_with_edge_options.html"))
# %%

# influence_man_data
influence_man.columns = ["influencer_name", "influence_value"]
influence_man_full_data = pd.merge(influence_man,
                                   influence_man_data,
                                   on=['influencer_name'])
influence_man_full_data = influence_man_full_data.drop_duplicates(
    "influencer_name")
nodes = [{
    "x": node["x"],
    "y": node["y"],
    "id": node["id"],
    "name": node["label"],
    "symbolSize": node["size"],
    "itemStyle": {
        "normal": {
            "color": node["color"]
        }
    },
} for node in data["nodes"]]

edges = [{
    "source": edge["sourceID"],
    "target": edge["targetID"]
} for edge in data["edges"]]

(Graph().add(
    series_name="",
    nodes=nodes,
    links=edges,
    layout="none",
    is_roam=True,
    is_focusnode=True,
    label_opts=opts.LabelOpts(is_show=False),
    linestyle_opts=opts.LineStyleOpts(width=0.5, curve=0.3, opacity=0.7),
).set_global_opts(title_opts=opts.TitleOpts(
    title="NPM Dependencies")).render("npm_dependencies.html"))
Esempio n. 20
0
     textstyle_opts=opts.TextStyleOpts(
         color='#fff'
     )
 ),
 tooltip_opts=opts.TooltipOpts(
     trigger="axis",
     axis_pointer_type="shadow",
     textstyle_opts=opts.TextStyleOpts(
         color="#fff"
     )
 ),
 xaxis_opts=opts.AxisOpts(
     type_="category",
     axisline_opts=opts.AxisLineOpts(
         linestyle_opts=opts.LineStyleOpts(
             color="white"
         )
     ),
     axislabel_opts=opts.LabelOpts(
     )
 ),
 yaxis_opts=opts.AxisOpts(
     type_="value",
     max_=90,
     axistick_opts=opts.AxisTickOpts(
         is_show=False
     ),
     splitline_opts=opts.SplitLineOpts(
         is_show=True,
         linestyle_opts=opts.LineStyleOpts(
             color='rgba(255,255,255,0.3)'
def levelRender(title, source, depList):
    #构建依赖关系图参数
    dataLevels = dependLevels(depList,source)
        
    #设置echart节点参数
    nodes = [
        {
            "x": node["x"],
            "y": node["y"],
            "id": node["name"],
            "name": node["name"],
            "value": "123",
            "symbol":"roundRect",
            "symbolSize": [5 + dataLevels.maxDeep - node["deep"], 5 + dataLevels.maxDeep - node["deep"]],
            "itemStyle": {"normal": {"color": 'green'}}
            #"label":{"formatter": "{c}"}
        }
        for node in dataLevels.nodes
    ]
    
    #设置边
    edges = [
        {
            "source": edge["parent"], 
            "target": edge["child"],
            "lineStyle":opts.LineStyleOpts
                (
                    width=2 if edge["is_circle"] is True else 0.5, 
                    curve=0.1, 
                    opacity=0.7,
                    color= 'blue' if edge["is_circle"] is True else 'grey' 
                )
        }
        for edge in dataLevels.deps
    ]
    
    #配置Graph关系图
    g = (
        Graph(init_opts=opts.InitOpts(width="1800px", height="1200px"))
        .add(
            series_name="",
            nodes=nodes,
            links=edges,
            layout="none",
            is_roam=True,
            is_focusnode=True,
            label_opts=opts.LabelOpts(is_show=True, color='red',position='top'),
            #linestyle_opts=opts.LineStyleOpts(width=0.5, curve=0.1, opacity=0.7),
            edge_label=opts.LabelOpts(
                    is_show=False, 
                    position="middle", 
                    formatter="{b}"
                ),
            edge_symbol =  ['none', 'arrow']
        )
        .set_global_opts(title_opts=opts.TitleOpts(title=title))
        .set_series_opts(
            emphasis = {
                "edgeLabel": opts.LabelOpts(
                    is_show=True, 
                    position="middle", 
                    formatter="{b}"
                )
            }
        )
        #.render(file)
    )
    return g
Esempio n. 22
0
def print_line():
    x_data = range(0, len(Grid))
    timeline2 = Timeline(init_opts=opts.InitOpts(bg_color="black"))
    for i in range(len(Grid)):
        line = (Line(init_opts=opts.InitOpts(bg_color="black")).add_xaxis(
            xaxis_data=time[0:i + 1]).add_yaxis(
                series_name="grid",
                y_axis=Grid[0:i + 1],
                is_smooth=True,
                label_opts=opts.LabelOpts(is_show=False),
                linestyle_opts=opts.LineStyleOpts(
                    width=3,
                    color="rgb(255,0,255)",
                ),
                color="rgb(255,255,0)",
                symbol="diamond",
                symbol_size=2,
            ).add_yaxis(
                series_name="pv",
                y_axis=PV[0:i + 1],
                is_smooth=True,
                label_opts=opts.LabelOpts(is_show=False),
                linestyle_opts=opts.LineStyleOpts(width=3,
                                                  color="rgb(0,255,255)"),
                color="rgb(255,255,255)",
                symbol="circle",
                symbol_size=2,
            ).add_yaxis(
                series_name="battery",
                y_axis=Battery[0:i + 1],
                is_smooth=True,
                label_opts=opts.LabelOpts(is_show=False),
                linestyle_opts=opts.LineStyleOpts(width=3,
                                                  color="rgb(255,255,255)"),
                color="rgb(0,255,255)",
                symbol="triangle",
                symbol_size=2,
            ).add_yaxis(
                series_name="demand",
                y_axis=demand[0:i + 1],
                is_smooth=True,
                label_opts=opts.LabelOpts(is_show=False),
                linestyle_opts=opts.LineStyleOpts(width=3,
                                                  color="rgb(255,255,0)"),
                color="rgb(255,0,255)",
                symbol="rect",
                symbol_size=2,
            ).set_global_opts(
                title_opts=opts.TitleOpts(
                    title="PV, battery, demand, grid(kW) till time {}".format(
                        time[i]),
                    title_textstyle_opts=opts.TextStyleOpts(color="white")),
                tooltip_opts=opts.TooltipOpts(trigger="axis",
                                              axis_pointer_type="none"),
                xaxis_opts=opts.AxisOpts(
                    boundary_gap=False,
                    min_='dataMin',
                    max_='dataMax',
                    axisline_opts=opts.AxisLineOpts(
                        linestyle_opts=opts.LineStyleOpts(color="white"), ),
                    axislabel_opts=opts.LabelOpts(),
                ),
                yaxis_opts=opts.AxisOpts(
                    axislabel_opts=opts.LabelOpts(formatter="{value}"),
                    axisline_opts=opts.AxisLineOpts(
                        linestyle_opts=opts.LineStyleOpts(color="white")),
                    splitline_opts=opts.SplitLineOpts(is_show=True),
                ),
                visualmap_opts=opts.VisualMapOpts(
                    is_show=False,
                    is_piecewise=False,
                    dimension=0,
                    textstyle_opts=opts.TextStyleOpts(color="white")),
                legend_opts=opts.LegendOpts(
                    textstyle_opts=opts.TextStyleOpts(color="white"),
                    pos_left="right",
                    pos_top="5%"),
            ))
        timeline2.add(line, "{}年".format(i)).add_schema(play_interval=2000,
                                                        is_auto_play=True,
                                                        is_timeline_show=False)
    timeline2.render("C:/Users/suqi/Desktop/allcode/linenew.html")
Esempio n. 23
0
def bar_line(request):
    """各种类型房屋的平均价格和数量 柱状图——折线图"""

    districts = []  # 区县名称
    infos = {}  # 各类新房的总数和均价
    # {'商业': [821, 21854707.0], '住宅': [567, 6424626.0], '别墅': [79, 1200119.0], '写字楼': [77, 1120913.0]}

    cursor = Mongo().connect_mongo('runoob', 'test').find()
    for data in cursor:
        if data["district"] not in districts:  # 获取区县
            districts.append(data["district"])

        if data["type"] not in infos:
            infos[data["type"]] = [1, float(data["price"])]
        else:
            infos[data["type"]][0] += 1
            infos[data["type"]][-1] += float(data["price"])

    x_data = [x for x in infos.keys()]
    bar = (
        Bar()
        .add_xaxis(x_data)
        .add_yaxis(
            "平均价格",
            ["{:.2f}".format(x[-1]/x[0]) for x in infos.values()],
            yaxis_index=0,
            color="#675bba",
            category_gap="65%",
        )

        .extend_axis(
            yaxis=opts.AxisOpts(
                name="",
                type_="value",
                # min_=0,
                # max_=250,
                position="right",
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(color="#675bba")
                ),
                axislabel_opts=opts.LabelOpts(formatter="{value}"),
            )
        )

        .extend_axis(
            yaxis=opts.AxisOpts(
                type_="value",
                name="",
                # min_=0,
                # max_=25,
                position="none",
                axisline_opts=opts.AxisLineOpts(
                    linestyle_opts=opts.LineStyleOpts(color="#d14a61")
                ),
                axislabel_opts=opts.LabelOpts(formatter="{value}"),
                splitline_opts=opts.SplitLineOpts(
                    is_show=False, linestyle_opts=opts.LineStyleOpts(opacity=1)
                )
            )
        )

        .set_global_opts(
            title_opts=opts.TitleOpts(title="成都各种类型新房价格与数量")
        )
    )

    line = (
        Line()
        .add_xaxis(x_data)
        .add_yaxis(
            "新房数量",
            ["{}".format(x[0]) for x in infos.values()],
            yaxis_index=2,
            color="#675bba",
            label_opts=opts.LabelOpts(is_show=True),
        )
    )

    bar.overlap(line)

    bar.overlap(line).render("templates/barline.html")
    return HttpResponse(bar.overlap(line).render_embed())
Esempio n. 24
0
def tradeDataShowKLine(product_code, ma=None, autoType=None) -> Grid:
    '''
    展示该产品的K线图,默认前复权,等值等比例的展示
    :param product_code: 产品代码
    :param ma=[30,60,99,120,250] 均线
    :param autoType: autoType=qfq-前复权 hfq-后复权 None-不复权
    :param *avg_line: 均线   暂时不做
    :return: 
    '''
    ma = [30, 60, 99, 120, 250] if ma is None else ma
    (productname,
     tradeDataDf) = sttradepb.getTradeDataFromDataBase(product_code,
                                                       ma,
                                                       autotype=autoType)
    tradeDataDf = tradeDataDf.where(tradeDataDf.notnull(), None)
    workDateList = tradeDataDf['trade_date'].tolist()
    workDateList = list(map(str, workDateList))

    # open,close,low,high数据获取
    new_data = tradeDataDf.loc[:, gc.PRICE_COLS].values
    tradeDataList = new_data.tolist()

    kline = (Kline().add_xaxis(xaxis_data=workDateList).add_yaxis(
        series_name="kline",
        y_axis=tradeDataList,
        itemstyle_opts=opts.ItemStyleOpts(color="#ec0000", color0="#00da3c"),
    ).set_global_opts(
        title_opts=opts.TitleOpts(
            title=productname + "(%s)" % product_code,
            subtitle="MA%s" % str(ma),
        ),
        xaxis_opts=opts.AxisOpts(type_="category"),
        yaxis_opts=opts.AxisOpts(
            is_scale=True,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        ),
        legend_opts=opts.LegendOpts(is_show=False,
                                    pos_bottom=10,
                                    pos_left="center"),
        datazoom_opts=[
            opts.DataZoomOpts(
                is_show=False,
                type_="inside",
                xaxis_index=[0, 1],
                range_start=0,
                range_end=100,
            ),
            opts.DataZoomOpts(
                is_show=True,
                xaxis_index=[0, 1],
                type_="slider",
                pos_top="90%",
                range_start=0,
                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"),
        ),
        visualmap_opts=opts.VisualMapOpts(
            is_show=False,
            dimension=2,
            series_index=5,
            is_piecewise=True,
            pieces=[
                {
                    "value": 1,
                    "color": "#ec0000"
                },
                {
                    "value": -1,
                    "color": "#00da3c"
                },
            ],
        ),
        axispointer_opts=opts.AxisPointerOpts(
            is_show=True,
            link=[{
                "xAxisIndex": "all"
            }],
            label=opts.LabelOpts(background_color="#777"),
        ),
        brush_opts=opts.BrushOpts(
            x_axis_index="all",
            brush_link="all",
            out_of_brush={"colorAlpha": 0.1},
            brush_type="lineX",
        ),
    ))

    line = (Line().add_xaxis(xaxis_data=workDateList).add_yaxis(
        series_name="MA%s" % ma[0],
        y_axis=tradeDataDf.loc[:, 'ma%s' % ma[0]].values.tolist(),
        is_smooth=True,
        is_hover_animation=False,
        linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    ).add_yaxis(
        series_name="MA%s" % ma[1],
        y_axis=tradeDataDf.loc[:, 'ma%s' % ma[1]].values.tolist(),
        is_smooth=True,
        is_hover_animation=False,
        linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    ).add_yaxis(
        series_name="MA%s" % ma[2],
        y_axis=tradeDataDf.loc[:, 'ma%s' % ma[2]].values.tolist(),
        is_smooth=True,
        is_hover_animation=False,
        linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    ).add_yaxis(
        series_name="MA%s" % ma[3],
        y_axis=tradeDataDf.loc[:, 'ma%s' % ma[3]].values.tolist(),
        is_smooth=True,
        is_hover_animation=False,
        linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    ).add_yaxis(
        series_name="MA%s" % ma[4],
        y_axis=tradeDataDf.loc[:, 'ma%s' % ma[4]].values.tolist(),
        is_smooth=True,
        is_hover_animation=False,
        linestyle_opts=opts.LineStyleOpts(width=3, opacity=0.5),
        label_opts=opts.LabelOpts(is_show=False),
    ).set_global_opts(xaxis_opts=opts.AxisOpts(type_="category")))

    bar = (Bar().add_xaxis(xaxis_data=workDateList).add_yaxis(
        series_name="Volume",
        yaxis_data=tradeDataDf.loc[:, "volume"].values.tolist(),
        xaxis_index=1,
        yaxis_index=1,
        label_opts=opts.LabelOpts(is_show=False),
    ).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(
            grid_index=1,
            is_scale=True,
            split_number=2,
            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),
    ))

    # Kline And Line
    overlap_kline_line = kline.overlap(line)

    # Grid Overlap + Bar
    grid_chart = Grid()
    grid_chart.add(
        overlap_kline_line,
        grid_opts=opts.GridOpts(pos_left="10%", pos_right="8%", height="50%"),
    )
    grid_chart.add(
        bar,
        grid_opts=opts.GridOpts(pos_left="10%",
                                pos_right="8%",
                                pos_top="70%",
                                height="16%"),
    )
    return grid_chart
Esempio n. 25
0
                },
                {
                    "featureType": "manmade",
                    "elementType": "all",
                    "stylers": {
                        "color": "#022338"
                    },
                },
                {
                    "featureType": "label",
                    "elementType": "all",
                    "stylers": {
                        "visibility": "off"
                    },
                },
            ]
        },
    ).add(
        "",
        type_="lines",
        is_polyline=True,
        data_pair=bus_lines,
        linestyle_opts=opts.LineStyleOpts(opacity=0.2, width=0.5),
        # 如果不是最新版本的话可以注释下面的参数(效果差距不大)
        progressive=200,
        progressive_threshold=500,
    ))

c.width = "100%"
put_html(c.render_notebook())
"""
v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]

(Radar(init_opts=opts.InitOpts(
    width="1600px", height="1000px", bg_color="#CCCCCC")).add_schema(
        schema=[
            opts.RadarIndicatorItem(name="销售(sales)", max_=6500),
            opts.RadarIndicatorItem(name="管理(Administration)", max_=16000),
            opts.RadarIndicatorItem(name="信息技术(Information Technology)",
                                    max_=30000),
            opts.RadarIndicatorItem(name="客服(Customer Support)", max_=38000),
            opts.RadarIndicatorItem(name="研发(Development)", max_=52000),
            opts.RadarIndicatorItem(name="市场(Marketing)", max_=25000),
        ],
        splitarea_opt=opts.SplitAreaOpts(
            is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        textstyle_opts=opts.TextStyleOpts(color="#fff"),
    ).add(
        series_name="预算分配(Allocated Budget)",
        data=v1,
        linestyle_opts=opts.LineStyleOpts(color="#CD0000"),
    ).add(
        series_name="实际开销(Actual Spending)",
        data=v2,
        linestyle_opts=opts.LineStyleOpts(color="#5CACEE"),
    ).set_series_opts(label_opts=opts.LabelOpts(
        is_show=False)).set_global_opts(
            title_opts=opts.TitleOpts(title="基础雷达图"),
            legend_opts=opts.LegendOpts()).render("basic_radar_chart.html"))
    400,
    500,
    600,
    750,
    800,
    700,
    600,
    400,
]

(Line().add_xaxis(xaxis_data=x_data).add_yaxis(
    series_name="用电量",
    y_axis=y_data,
    is_smooth=True,
    label_opts=opts.LabelOpts(is_show=False),
    linestyle_opts=opts.LineStyleOpts(width=2),
).set_global_opts(
    title_opts=opts.TitleOpts(title="一天用电量分布", subtitle="纯属虚构"),
    tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
    xaxis_opts=opts.AxisOpts(boundary_gap=False),
    yaxis_opts=opts.AxisOpts(
        axislabel_opts=opts.LabelOpts(formatter="{value} W"),
        splitline_opts=opts.SplitLineOpts(is_show=True),
    ),
    visualmap_opts=opts.VisualMapOpts(
        is_piecewise=True,
        dimension=0,
        pieces=[
            {
                "lte": 6,
                "color": "green"
from pyecharts import options as opts
from pyecharts.charts import Gauge

c = (Gauge().add(
    "业务指标",
    [("完成率", 55.5)],
    split_number=5,
    axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(
        color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=30)),
    detail_label_opts=opts.LabelOpts(formatter="{value}"),
).set_global_opts(
    title_opts=opts.TitleOpts(title="Gauge-分割段数-Label"),
    legend_opts=opts.LegendOpts(is_show=False),
).render("gauge_splitnum_label.html"))
                "stylers": {
                    "color": "#d1d1d1"
                },
            },
            {
                "featureType": "label",
                "elementType": "labels.text.fill",
                "stylers": {
                    "color": "#999999"
                },
            },
        ]
    },
).add(
    series_name="",
    type_=ChartType.LINES,
    data_pair=map_data,
    is_polyline=True,
    is_large=True,
    linestyle_opts=opts.LineStyleOpts(color="purple", opacity=0.6, width=1),
    effect_opts=opts.EffectOpts(trail_length=0.5),
).add_control_panel(
    copyright_control_opts=opts.BMapCopyrightTypeOpts(position=3),
    maptype_control_opts=opts.BMapTypeControlOpts(
        type_=BMapType.MAPTYPE_CONTROL_DROPDOWN),
    scale_control_opts=opts.BMapScaleControlOpts(),
    overview_map_opts=opts.BMapOverviewMapControlOpts(is_open=True),
    navigation_control_opts=opts.BMapNavigationControlOpts(),
    geo_location_control_opts=opts.BMapGeoLocationControlOpts(),
).render("hiking_trail_in_hangzhou.html"))
Esempio n. 30
0
def confirm_line(request):
    '''
    确诊/疑似折线图,以json返回
    '''
    line2 = (
        Line()
        .add_xaxis(cure_data['updateDate'])
        .add_yaxis('确诊', cure_data['list'][0]['data'],color='#f9b97c',linestyle_opts = opts.LineStyleOpts(width=2),is_smooth=True,label_opts=opts.LabelOpts(is_show=False))
        .add_yaxis('疑似', cure_data['list'][1]['data'],color='#ae212c',linestyle_opts = opts.LineStyleOpts(width=2),is_smooth=True,label_opts=opts.LabelOpts(is_show=False))

        .set_global_opts(
        title_opts=opts.TitleOpts(title='确诊/疑似累计趋势图',pos_top='top'),
        xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            splitline_opts=opts.SplitLineOpts(is_show=True),
            axisline_opts=opts.AxisLineOpts(is_show=False),
        ),
        tooltip_opts=opts.TooltipOpts(
            is_show=True, trigger="axis", axis_pointer_type="cross",
        ),
        )
        .dump_options_with_quotes()
    )
    return JsonResponse(json.loads(line2))