Пример #1
0
line = Line("折线图示例", width = 1200)
attr_line = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
data1_line = [11, 11, 15, 13, 12, 13, 10]
data2_line = [1, -2, 2, 5, 3, 2, 0]
line.add("最高气温", 
		 attr_line, data1_line, 
		 mark_point = ["max", "min"], 
		 mark_line = ["average"])
line.add("最低气温", 
		 attr_line, data2_line,
		 mark_point = ["max", "min"], 
		 mark_line = ["avergae"], 
		 legend_pos = "20%")

# Pie
attr_pie = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
data_pie = [11, 12, 13, 10, 10, 10]
pie = Pie("饼图示例", title_pos = "45%")
pie.add("", 
		attr_pie, data_pie, 
		radius = [30, 55],
		legend_pos = "65%",
		legend_orient = "horizonial")

# Grid
grid = Grid()
grid.add(line, grid_right = "65%")
grid.add(pie, grid_left = "60%")
grid.render("/home/wangzhefeng/project/DataVisualiztion/pyecharts/grid_test.html")
make_a_snapshot("grid_test.html", "grid_test.pdf")
Пример #2
0
def PL_draw_echarts(PL_df, PL_slices):
    # 初始化一个画图的页面.每一种信号画一张图片
    PL_page = Page()
    PL_columns = PL_df.columns.values.tolist()
    # 所有统计的信号种类
    PL_signal_items = list(set(PL_df['signal_name'].tolist()))
    PL_signal_items.sort()

    # 所有的N[第n个bar]
    PL_bar_nos = []
    for PL_col in PL_columns:
        if re.match('chg_pct_', PL_col):
            # 获取当前统计的是第几根bar的收益
            PL_bar_nos.append(PL_col.replace('chg_pct_', ''))

    for PL_sig in PL_signal_items:
        # 获取一种信号在M个bar内的收益统计
        PL_bar = Bar(PL_sig + "收益分布", title_text_size=14, width='100%')

        PL_sdf = PL_df[(PL_df['signal_name'] == PL_sig)]
        if PL_sdf.empty:
            continue

        # 划分收益区间,从0开始往正负两端划分收益区间
        # 计算每个收益区间的大小
        PL_max_profit = 0
        PL_min_profit = 0
        for PL_no in PL_bar_nos:
            PL_pcol = 'chg_pct_' + PL_no
            PL_profits = PL_sdf[PL_pcol].tolist()
            PL_max_profit = max(max(PL_profits), PL_max_profit)
            PL_min_profit = min(min(PL_profits), PL_min_profit)
        PL_intervals = []
        if PL_min_profit < 0:
            PL_unit = round(
                max(PL_max_profit, abs(PL_min_profit)) / PL_slices, 4)
            # 先划分小于0的区间
            for i in range(0, int(math.ceil(abs(PL_min_profit) / PL_unit))):
                PL_intervals.append(
                    [round(-(i + 1) * PL_unit, 4),
                     round(-i * PL_unit, 4)])
            PL_intervals.reverse()
        else:
            PL_unit = PL_max_profit / PL_slices

        for i in range(0, int(math.ceil(abs(PL_max_profit) / PL_unit))):
            PL_intervals.append([i * PL_unit, (i + 1) * PL_unit])

        # 显示收益区间之前先格式化成百分比。
        PL_format_intervals = [
            '%.2f%%~%.2f%%' % (i[0] * 100, i[1] * 100) for i in PL_intervals
        ]

        for PL_no in PL_bar_nos:
            # 计算第M个bar收益,落在某一个收益区间的概率
            PL_win_ratios = []
            PL_pcol = 'chg_pct_' + PL_no
            for PL_interval in PL_intervals:
                # 统计在收益落在某个收益区间的概率
                PL_conf = (PL_sdf[PL_pcol] > PL_interval[0]) & (
                    PL_sdf[PL_pcol] <= PL_interval[1])
                # 避免int类型直接除之后返回的还是int,这里*1.0
                PL_win_ratios.append(
                    round(len(PL_sdf[PL_conf]) / (len(PL_sdf) * 1.0), 2))
            PL_bar.add(
                "第%s个bar" % PL_no,
                PL_format_intervals,
                PL_win_ratios,
                xaxis_name='收益区间',
                xaxis_name_pos='end',
                xaxis_name_size=12,
                xaxis_label_textsize=12,
                xaxis_interval=1,
                xaxis_rotate=45,
                yaxis_name='概率',
                yaxis_name_pos='end',
                yaxis_name_size=12,
                yaxis_label_textsize=12,
                is_splitline_show=False,
                # 默认为 X 轴,横向
                is_datazoom_show=True,
                datazoom_type="both",
                datazoom_range=[40, 60],
                # 额外的 dataZoom 控制条,纵向
                # is_datazoom_extra_show=True,
                # datazoom_extra_type="slider",
                # datazoom_extra_range=[10, 25],
                # is_toolbox_show=False,
            )
        PL_grid = Grid(width='100%')
        PL_grid.add(PL_bar, grid_bottom=120)
        PL_page.add(PL_grid)

    PL_page.render()
Пример #3
0
from pyecharts import Bar, Grid

x = [
    "名字很长的x轴1",
    "名字很长的x轴2",
    "名字很长的x轴3",
    "名字很长的x轴4",
    "名字很长的x轴5",
    "名字很长的x轴6",
    "名字很长的x轴7",
    "名字很长的x轴8",
    "名字很长的x轴9",
]
y = [10, 20, 30, 40, 50, 60, 70, 80, 90]

grid = Grid()
bar = Bar("利用 Grid 解决 dataZoom 与 X 轴标签重叠问题")
bar.add("", x, y, is_datazoom_show=True, xaxis_interval=0, xaxis_rotate=30)
# 把 bar 加入到 grid 中,并适当调整 grid_bottom 参数,使 bar 图整体上移
grid.add(bar, grid_bottom="25%")
grid.render()
Пример #4
0
def test_grid_multiple_datazoom_index():
    line = Line("折线图示例", width=1200, height=700)
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        legend_top="50%",
        mark_line=["average"],
        is_datazoom_show=True,
        datazoom_xaxis_index=[0, 1],
    )

    v1 = [
        [2320.26, 2320.26, 2287.3, 2362.94],
        [2300, 2291.3, 2288.26, 2308.38],
        [2295.35, 2346.5, 2295.35, 2345.92],
        [2347.22, 2358.98, 2337.35, 2363.8],
        [2360.75, 2382.48, 2347.89, 2383.76],
        [2383.43, 2385.42, 2371.23, 2391.82],
        [2377.41, 2419.02, 2369.57, 2421.15],
        [2425.92, 2428.15, 2417.58, 2440.38],
        [2411, 2433.13, 2403.3, 2437.42],
        [2432.68, 2334.48, 2427.7, 2441.73],
        [2430.69, 2418.53, 2394.22, 2433.89],
        [2416.62, 2432.4, 2414.4, 2443.03],
        [2441.91, 2421.56, 2418.43, 2444.8],
        [2420.26, 2382.91, 2373.53, 2427.07],
        [2383.49, 2397.18, 2370.61, 2397.94],
        [2378.82, 2325.95, 2309.17, 2378.82],
        [2322.94, 2314.16, 2308.76, 2330.88],
        [2320.62, 2325.82, 2315.01, 2338.78],
        [2313.74, 2293.34, 2289.89, 2340.71],
        [2297.77, 2313.22, 2292.03, 2324.63],
        [2322.32, 2365.59, 2308.92, 2366.16],
        [2364.54, 2359.51, 2330.86, 2369.65],
        [2332.08, 2273.4, 2259.25, 2333.54],
        [2274.81, 2326.31, 2270.1, 2328.14],
        [2333.61, 2347.18, 2321.6, 2351.44],
        [2340.44, 2324.29, 2304.27, 2352.02],
        [2326.42, 2318.61, 2314.59, 2333.67],
        [2314.68, 2310.59, 2296.58, 2320.96],
        [2309.16, 2286.6, 2264.83, 2333.29],
        [2282.17, 2263.97, 2253.25, 2286.33],
        [2255.77, 2270.28, 2253.31, 2276.22],
    ]
    kline = Kline("K 线图示例", title_top="50%")
    kline.add(
        "日K",
        ["2017/7/{}".format(i + 1) for i in range(31)],
        v1,
        is_datazoom_show=True,
    )

    grid = Grid()
    grid.add(line, grid_top="60%")
    grid.add(kline, grid_bottom="60%")
    grid.render()
Пример #5
0
    "Wednesday",
    "Tuesday",
    "Monday",
    "Sunday",
]
data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)]
heatmap = HeatMap("热力图示例")
heatmap.add(
    "热力图直角坐标系",
    x_axis,
    y_axis,
    data,
    is_visualmap=True,
    visual_top="45%",
    visual_text_color="#000",
    visual_orient="horizontal",
)
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
bar = Bar("柱状图示例", title_top="52%")
bar.add("商家A", attr, v1, is_stack=True)
bar.add("商家B", attr, v2, is_stack=True, legend_top="50%")

grid = Grid(height=700)
grid.add(heatmap, grid_bottom="60%")
grid.add(bar, grid_top="60%")

page.add(grid)
page.render('./grid01.html')
Пример #6
0
def bar_chart():
    ggu = tableau_services.get_growthOfunit(**g.my_dict)
    timestr = ggu['growth_of_unit']['xAxis']
    timestr = [i[:-9] for i in timestr]
    attr = timestr
    vs = "v" + "s"
    print(vs)
    1 + 1 = 3
    print(vs)
    v1 = ggu['growth_of_unit']['series']['DEMOXYZ9'][1]
    v2 = ggu['growth_of_unit']['series']['DEMOXYZ9'][2]
    v3 = ggu['growth_of_unit']['series']['DEMOXYZ6'][1]
    v4 = ggu['growth_of_unit']['series']['DEMOXYZ6'][2]
    v5 = ggu['growth_of_unit']['series']['DEMOXYZ8'][1]
    v6 = ggu['growth_of_unit']['series']['DEMOXYZ8'][2]
    bar = Bar(" ")
    bar.add("DEMOXYZ9",
            attr,
            v1,
            is_convert=True,
            legend_text_size=18,
            is_datazoom_show=True,
            datazoom_type="both")
    bar.add("DEMOXYZ9",
            attr,
            v2,
            is_convert=True,
            legend_text_size=18,
            is_datazoom_show=True,
            datazoom_type="both")
    bar.add("DEMOXYZ6",
            attr,
            v3,
            is_convert=True,
            legend_text_size=18,
            is_datazoom_show=True,
            datazoom_type="both")
    bar.add("DEMOXYZ6",
            attr,
            v4,
            is_convert=True,
            legend_text_size=18,
            is_datazoom_show=True,
            datazoom_type="both")
    bar.add("DEMOXYZ8",
            attr,
            v5,
            is_convert=True,
            legend_text_size=18,
            is_datazoom_show=True,
            datazoom_type="both")
    bar.add("DEMOXYZ8",
            attr,
            v6,
            is_convert=True,
            legend_text_size=18,
            is_datazoom_show=True,
            datazoom_type="both")

    line = Line(" ")
    line.add("DEMOXYZ9",
             timestr,
             ggu['growth_of_unit']['series']['DEMOXYZ9'][1],
             is_stack=True,
             is_label_show=True,
             legend_top="50%",
             is_datazoom_show=True,
             is_legend_show=False,
             datazoom_type="both")
    line.add("DEMOXYZ9",
             timestr,
             ggu['growth_of_unit']['series']['DEMOXYZ9'][2],
             is_stack=True,
             is_label_show=True,
             legend_top="50%",
             is_datazoom_show=True,
             is_legend_show=False,
             datazoom_type="both")
    line.add("DEMOXYZ6",
             timestr,
             ggu['growth_of_unit']['series']['DEMOXYZ6'][1],
             is_stack=True,
             is_label_show=True,
             legend_top="50%",
             is_datazoom_show=True,
             is_legend_show=False,
             datazoom_type="both")
    line.add("DEMOXYZ6",
             timestr,
             ggu['growth_of_unit']['series']['DEMOXYZ6'][2],
             is_stack=True,
             is_label_show=True,
             legend_top="50%",
             is_datazoom_show=True,
             is_legend_show=False,
             datazoom_type="both")
    line.add("DEMOXYZ8",
             timestr,
             ggu['growth_of_unit']['series']['DEMOXYZ8'][1],
             is_stack=True,
             is_label_show=True,
             legend_top="50%",
             is_datazoom_show=True,
             is_legend_show=False,
             datazoom_type="both")
    line.add("DEMOXYZ8",
             timestr,
             ggu['growth_of_unit']['series']['DEMOXYZ8'][2],
             is_stack=True,
             is_label_show=True,
             legend_top="50%",
             is_datazoom_show=True,
             is_legend_show=False,
             datazoom_type="both")
    grid = Grid()
    grid.add(bar, grid_right="50%")
    grid.add(line, grid_left="60%")
    return grid
Пример #7
0
bb_peoples = []
for i in bb_data:
    bb_times.append(i[0])
    j = json.dumps(i[1], cls=DecimalEncoder)
    bb_peoples.append(j)

# 张思强组
zsq_times = []
zsq_peoples = []
for i in zsq_data:
    zsq_times.append(i[0])
    j = json.dumps(i[1], cls=DecimalEncoder)
    zsq_peoples.append(j)

line_sound = Line("各部门开播主播趋势图", title_pos='50%')
line_sound.add("池珊组", cs_times, cs_peoples, mark_point=["max, min"], mark_line=['average'], legend_pos='70%')
line_sound.add("希文组", xw_times, xw_peoples, mark_point=["max, min"], mark_line=['average'], legend_pos='70%')
line_sound.add("北北组", bb_times, bb_peoples, mark_point=["max, min"], mark_line=['average'], legend_pos='70%')
line_sound.add("张思强组", zsq_times, zsq_peoples, mark_point=["max, min"], mark_line=['average'], legend_pos='70%')




grid = Grid(height=720, width=1500)
grid.add(line1, grid_top='60%', grid_right='60%')
grid.add(line_open, grid_top='60%', grid_left='60%')
grid.add(line2, grid_bottom='60%', grid_right='60%')
grid.add(line_sound, grid_bottom='60%', grid_left='60%')


grid.render('line01.html')
Пример #8
0
         days0,
         radius=[45, 65],
         center=[20, 50],
         is_label_show=True,
         legend_orient='vertical',
         legend_pos="40%",
         label_text_size=10,
         mark_point=['max'])
# bar.render(path = 'D:\\示例1.jpeg')

sheet1 = pd.read_excel("./data_resources/3.3各组出差费用密度.xls")
group1 = sheet1["组名"].values.tolist()
days1 = sheet1["各组出差成本的密度"].values.tolist()
pie1 = Pie('各组出差成本的密度', title_pos="55%")
pie1.add('组名',
         group1,
         days1,
         radius=[45, 65],
         center=[65, 50],
         is_label_show=True,
         legend_orient='vertical',
         legend_pos="85%",
         label_text_size=10,
         mark_point=['max'])
# bar.render(path = 'D:\\示例1.jpeg')

grid = Grid(width=1200)
grid.add(pie0, grid_right="55%")
# grid.render("./all_charts/"+"各组出差天数费用0.xls"+".html")
grid.add(pie1, grid_left="50%")
grid.render("./all_charts/" + "3.1_3.3每个组的出差成本密度" + ".html")
Пример #9
0
class HKUFigure(object):
    def __init__(self, width, height, num=1):
        if num < 1:
            self._num = 1
        elif num > 4:
            self._num = 4
        else:
            self._num = num

        self._added_flag = [False, False, False, False]
        self._grid = Grid(width=width, height=height)
        self._width = width
        self._height = height
        self._axis_num = {}
        self._axis_list = [None, None, None, None]
        for i in range(self._num):
            overlap = Overlap(width=width, height=height)
            self._axis_num[overlap] = i
            self._axis_list[i] = overlap
        self._current_axis = 0
        self._xaxis = None
        self._label_color = []

    def _repr_html_(self):
        return self.get_grid()._repr_html_()

    def get_current_axis(self):
        return self._axis_list[self._current_axis]

    def get_axis(self, pos):
        return self._axis_list[pos]

    def get_grid(self):
        return self._grid

    def set_xaxis(self, xaxis):
        self._xaxis = xaxis

    def get_xaxis(self):
        return self._xaxis

    def add_axis(self, axis):
        if axis not in self._axis_num:
            return

        pos = self._axis_num[axis]
        self._current_axis = pos
        self._added_flag[pos] = True
        self._flush()
        return axis

    def _flush(self):
        self._grid = Grid(width=self._width, height=self._height)
        for pos, axis in enumerate(self._axis_list):
            if axis is None or axis.options is None \
                or axis.options.get('yAxis') is None:
                continue

            if self._num == 1:
                self._grid.add(axis, grid_top="8%")

            elif self._num == 2:
                if pos == 0:
                    self._grid.add(axis, grid_top="8%", grid_height='52%')
                else:
                    self._grid.add(axis, grid_top="62%")

            elif self._num == 3:
                if pos == 0:
                    self._grid.add(axis, grid_top='8%', grid_height='40%')
                elif pos == 1:
                    self._grid.add(axis, grid_top='50%', grid_height='19%')
                else:
                    self._grid.add(axis, grid_bottom='10%', grid_height='19%')

            else:
                if pos == 0:
                    self._grid.add(axis, grid_top='8%', grid_height='30%')
                elif pos == 1:
                    self._grid.add(axis, grid_top='40%', grid_height='18%')
                elif pos == 2:
                    self._grid.add(axis, grid_top='60%', grid_height='15%')
                else:
                    self._grid.add(axis, grid_top='77%', grid_height='15%')

    def get_style(self, axis, **kwargs):
        pos = self._axis_num[axis]
        num = self._num
        style = Style()
        default_datazoom_type = 'both'
        result = None
        if num == 1:
            result = style.add(legend_text_size='10',
                               legend_top='8%',
                               legend_pos='10%',
                               legend_orient='vertical',
                               is_symbol_show=False,
                               is_datazoom_show=True,
                               datazoom_type=default_datazoom_type)

        elif num == 2:
            if pos == 0:
                result = style.add(legend_text_size='10',
                                   legend_top='8%',
                                   legend_pos='10%',
                                   legend_orient='vertical',
                                   is_symbol_show=False,
                                   is_datazoom_show=True,
                                   datazoom_type=default_datazoom_type,
                                   datazoom_xaxis_index=[0, 1],
                                   is_xaxis_show=False)
            else:
                result = style.add(
                    legend_text_size='10',
                    legend_top='62%',
                    legend_pos='10%',
                    #legend_orient='vertical',
                    is_symbol_show=False,
                    is_datazoom_show=True,
                    datazoom_type=default_datazoom_type,
                    datazoom_xaxis_index=[0, 1],
                    is_xaxis_show=True)

        elif num == 3:
            if pos == 0:
                result = style.add(legend_text_size='10',
                                   legend_top='8%',
                                   legend_pos='10%',
                                   legend_orient='vertical',
                                   is_symbol_show=False,
                                   is_datazoom_show=True,
                                   datazoom_type=default_datazoom_type,
                                   datazoom_xaxis_index=[0, 1, 2],
                                   is_xaxis_show=False)
            elif pos == 1:
                result = style.add(
                    legend_text_size='10',
                    legend_top='50%',
                    legend_pos='10%',
                    #legend_orient='vertical',
                    is_symbol_show=False,
                    is_datazoom_show=True,
                    datazoom_type=default_datazoom_type,
                    datazoom_xaxis_index=[0, 1, 2],
                    is_xaxis_show=False)
            else:
                result = style.add(
                    legend_text_size='10',
                    legend_top='71%',
                    legend_pos='10%',
                    #legend_orient='vertical',
                    is_symbol_show=False,
                    is_datazoom_show=True,
                    datazoom_type=default_datazoom_type,
                    datazoom_xaxis_index=[0, 1, 2],
                    is_xaxis_show=True)

        else:
            if pos == 0:
                result = style.add(legend_text_size='10',
                                   legend_top='8%',
                                   legend_pos='10%',
                                   legend_orient='vertical',
                                   is_symbol_show=False,
                                   is_datazoom_show=True,
                                   datazoom_type=default_datazoom_type,
                                   datazoom_xaxis_index=[0, 1, 2, 3],
                                   is_xaxis_show=False)
            elif pos == 1:
                result = style.add(
                    legend_text_size='10',
                    legend_top='40%',
                    legend_pos='10%',
                    #legend_orient='vertical',
                    is_symbol_show=False,
                    is_datazoom_show=True,
                    datazoom_type=default_datazoom_type,
                    datazoom_xaxis_index=[0, 1, 2, 3],
                    is_xaxis_show=False)
            elif pos == 2:
                result = style.add(
                    legend_text_size='10',
                    legend_top='60%',
                    legend_pos='10%',
                    #legend_orient='vertical',
                    is_symbol_show=False,
                    is_datazoom_show=True,
                    datazoom_type=default_datazoom_type,
                    datazoom_xaxis_index=[0, 1, 2, 3],
                    is_xaxis_show=False)
            else:
                result = style.add(
                    legend_text_size='10',
                    legend_top='77%',
                    legend_pos='10%',
                    #legend_orient='vertical',
                    is_symbol_show=False,
                    is_datazoom_show=True,
                    datazoom_type=default_datazoom_type,
                    datazoom_xaxis_index=[0, 1, 2, 3],
                    is_xaxis_show=True)

        color_map = {
            'r': '#CD0000',
            'g': '#008B00',
            'b': '#0000EE',
            'c': '#40E0D0',
            'm': '#CD00CD',
            'y': '#EE9A00',
            'k': '#000000',
            'w': '#FFFFFF'
        }

        line_map = {'-': 'solid', '--': 'dashed', ':': 'dotted'}

        for item in kwargs.items():
            if 'color' == item[0]:
                color = color_map[
                    item[1]] if item[1] in color_map else color_map['r']
                result['line_color'] = color
                self._label_color += [color]
                result['label_color'] = self._label_color

            elif 'linestyle' == item[0]:
                result['line_type'] = line_map[
                    item[1]] if item[1] in line_map else line_map['-']

            else:
                result[item[0]] = item[1]

        return result
Пример #10
0
attr_2=["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
v3=[11, 11, 15, 13, 12, 13, 10]
v4=[1, -2, 2, 5, 3, 2, 0]
line=Line('折线图示例')
line.add('最高气温',attr_2,v3,mark_point=['max','min'],mark_line=['average'])
line.add('最低气温',attr_2,v4,mark_point=['max','min'],mark_line=['average'],legend_pos='20%')

scatter=Scatter('散点图示例',title_top="50%", title_pos="65%")
v1=[5, 20, 36, 10, 75, 90]
v2=[10, 25, 8, 60, 20, 80]
scatter.add('scatter',
            v1,
            v2,
            legend_top="50%", legend_pos="80%")

effectscatter=EffectScatter('动态散点图示例',title_top="50%")
effectscatter.add('es',
                  [11, 11, 15, 13, 12, 13, 10],
                  [1, -2, 2, 5, 3, 2, 0],
                  effect_scale=6,
                  legend_top="50%",
                  legend_pos="20%",
                  )

grid=Grid(width=1200,height=720)
grid.add(bar,grid_bottom='60%',grid_left='60%')
grid.add(line,grid_bottom='60%',grid_right='60%')
grid.add(scatter,grid_top='60%',grid_left='60%')
grid.add(effectscatter,grid_top='60%',grid_right='60%')
grid.render()
Пример #11
0
def scatter(bq,output):
	page=Page()
	page.height=900
	c=0
	fc=18   #fontsize
	if len(bq.keys())>4:
		fig=plt.figure(figsize=(24,10))
	else:
		fig=plt.figure(figsize=(20,5))
	#fig.subplots_adjust(wspace=0.5,hspace=0.5)
	#iden the fig shape
	#2 col situation
	if len(bq.keys())%2==0 and len(bq.keys())%3!=0 and len(bq.keys())%4!=0:
		all_col=2
	elif len(bq.keys())%3==0:
		all_col=3
	elif len(bq.keys())%4==0:
		all_col=4
	#iden shape end
	if int(len(bq.keys())%all_col)==0:
		row=int(len(bq.keys())/all_col)
	else:
		row=int(len(bq.keys())/all_col)+1
	for key1 in bq:
		cp=[] #completeness
		ct=[] #contamination
		a=sorted(bq[key1]['completeness'].items(),key=lambda x:x[1],reverse=True) #sort keys  according to their values
		#c=0
		for e in a:
			cp.append(bq[key1]['completeness'][e[0]])
			ct.append(bq[key1]['contamination'][e[0]])
		c+=1
		x=range(1,len(cp)+1)
		##### literature  figure part #####
		#fig.subplots_adjust(wspace=0.3,hspace=0.6)
		if max(ct)>100:
			ax1=fig.add_subplot(row,all_col,c)
                        ax1.set_xlabel(key1,color='black',fontsize=fc)
                        ax1.set_ylabel('Completeness',fontsize=fc)
                        ax1.scatter(x,cp,color='black',label='Completeness')
                        ax2=ax1.twinx()
                        ax2.scatter(x,ct,color='red',label='Contamination')
                        ax2.set_ylabel('Contamination',color='black',fontsize=fc)
                        ax2.tick_params(axis='y',colors='red')
                        ax2.spines['right'].set_color('red')
			if max(ct)%10==0:
				max_10_ct=max(ct)
			else:
				max_10_ct=(10-max(ct)%10)+max(ct)
			ax2.axis([min(x),max(x),0,max_10_ct])
			ax1.axis([min(x),max(x),0,max_10_ct])
			#ax2.axis([min(x),max(x),0,max(cp)])
		else:
			ax1=fig.add_subplot(row,all_col,c)
			ax1.set_xlabel(key1,color='black',fontsize=fc)
			ax1.set_ylabel('Completeness',fontsize=fc)
			ax1.scatter(x,cp,color='black',label='Completeness')
			ax2=ax1.twinx()
			ax2.scatter(x,ct,color='red',label='Contamination')
			ax2.set_ylabel('Contamination',color='black',fontsize=fc)
			ax2.tick_params(axis='y',colors='red')
			ax2.spines['right'].set_color('red')
			ax2.axis([min(x),max(x),0,100])
		#plt.savefig(output+'/3.scatter.png')				
		##### literature  figure end  #####

		#x=range(1,len(cp)+1)
		#grid=Grid()
		#overlap = Overlap()
		#scatter = Scatter()
		#scatter2 = Scatter(key1)
		if c%2==0:
			#2
			if c%4!=0:
				overlap2 = Overlap()
		                scatter3 = Scatter()
				scatter3.add("Completeness",x,cp,yaxis_label_textcolor='red',yaxis_line_color='red',xaxis_type='category',xaxis_max=max(x),legend_pos="40%",legend_orient="vertical")
				scatter4 = Scatter(key1,title_pos="25%")
				scatter4.add('Contamination',x,ct,xaxis_type='category',xaxis_max=max(x),legend_pos="40%",legend_orient="vertical")
				overlap2.add(scatter4)
		                overlap2.add(scatter3)
			#4
			else:
				overlap4 = Overlap()
                                scatter7 = Scatter()
                                scatter7.add("Completeness",x,cp,yaxis_label_textcolor='red',yaxis_line_color='red',xaxis_type='category',xaxis_max=max(x),legend_pos="90%",legend_orient="vertical")
                                scatter8 = Scatter(key1,title_pos="75%")
                                scatter8.add('Contamination',x,ct,xaxis_type='category',xaxis_max=max(x),legend_pos="90%",legend_orient="vertical")
                                overlap4.add(scatter8)
                                overlap4.add(scatter7)
			#overlap2.render(output+'/3.scatter_o2.html')
		else:
			#1
			if (c+1)%4!=0:
				overlap = Overlap()
		                scatter = Scatter()
				scatter.add("Completeness",x,cp,yaxis_label_textcolor='red',yaxis_line_color='red',xaxis_type='category',xaxis_max=max(x),legend_pos="15%",legend_orient="vertical")
	                        scatter2 = Scatter(key1)
                        	scatter2.add('Contamination',x,ct,xaxis_type='category',xaxis_max=max(x),legend_pos="15%",legend_orient="vertical")
				overlap.add(scatter2)
				overlap.add(scatter)
			#3
			else:
				overlap3 = Overlap()
                                scatter5= Scatter()
                                scatter5.add("Completeness",x,cp,yaxis_label_textcolor='red',yaxis_line_color='red',xaxis_type='category',xaxis_max=max(x),legend_pos="65%",legend_orient="vertical")
                                scatter6= Scatter(key1,title_pos="50%")
                                scatter6.add('Contamination',x,ct,xaxis_type='category',xaxis_max=max(x),legend_pos="65%",legend_orient="vertical")
                                overlap3.add(scatter6)
                                overlap3.add(scatter5)
			#overlap.render(output+'/3.scatter_o1.html')
		'''
		if c==len(bq.keys()) and c%2!=0:
			grid=Grid()
                        grid.add(overlap,grid_left="60%")
			page.add(grid)
			continue
		'''
		if c%2==0:
			#2
			if c%4!=0:
				grid.add(overlap2,grid_left="30%",grid_width=250)
			#4
			else:
				grid.add(overlap4,grid_left="80%",grid_width=200)
                                page.add(grid)
			#grid.render(output+'/3.scatter.html')
			#page.render(output+'/3.scatter.html')
		else:
			#3
			if (c+1)%4==0:
				grid.add(overlap3, grid_left="55%",grid_width=250)
			#1
			else:
				grid=Grid()
				grid.width=1500
				grid.height=300
				grid.add(overlap,grid_left="5%",grid_width=250)
			#grid.render(output+'/3.scatter.html')
                        #page.render(output+'/3.scatter.html')
                        #exit()
		if c==len(bq.keys()) and c%4!=0:
			page.add(grid)
	page.render(output+'/3_scatter.html')
	#fig.subplots_adjust(wspace=0.3,hspace=0.3)
	#ax1.legend(loc='center', bbox_to_anchor=(-1.3, 3.8),ncol=5,fontsize=20)
	fig.subplots_adjust(wspace=0.5)
	plt.savefig(output+'/3.scatter.png')
Пример #12
0
attr = ['{}日'.format(i) for i in range(1, 32)]
line1.add("6月",
          attr,
          data3,
          line_opacity=1.9,
          is_symbol=True,
          legend_pos='70%')
line1.add("7月", attr, data4, is_smooth=True, legend_pos='70%')
line1.add("8月",
          attr,
          data5,
          line_opacity=1.9,
          area_opacity=0.6,
          is_symbol=True,
          legend_pos='70%')
grid = Grid(width=900, height=600)
grid.add(line1, grid_top="60%", grid_left="15%")
grid.add(line, grid_bottom="60%", grid_left="15%")
grid.render(path='C:/Users/lenovo/Downloads/Active.png')

# #累计月活图
# f,ax = plt.subplots(figsize = (8,16),nrows=2)
# # ax[0].plot(data1,'g.-',label = 'Aug')
# ax[0].plot(data3,'y.-',label = 'Mar')
# ax[0].plot(data4,'b.-',label = 'Apr')
# ax[0].plot(data5,'r.-',label = 'May')
# ax[0].legend(loc = 'best')
# ax[0].set_title("Monthly live")
# # ax[0].set_xlabel('Time')
# ax[0].set_ylabel('Nums_consum')
# ticks = ax[0].set_xticks(range(0,31))
#增加RSI指标模型
#改正了BAR 与 line 横坐标不能共享的 bug

import xlrd
from xlrd import xldate_as_tuple
from datetime import datetime
from pyecharts import Kline, Line, Overlap, Grid, Bar, Page

grid = Grid()


#导入 开 收 低 高
def Import():
    data = xlrd.open_workbook("Bitcoin - 比特币历史数据_历史行情,价格,走势图表.xlsx")
    table = data.sheets()[0]  #通过索引顺序获取

    time = table.col_values(0)  #获取日期指
    time.reverse()  #反转
    time.pop()  #去掉最后一个字符
    #将日期转化为 %Y/%m/%d 形式
    date = []
    for i in range(len(time)):
        date.append(
            datetime(*xldate_as_tuple(time[i], 0)).strftime('%Y/%m/%d'))

    print("导入时间:", date)

    close = table.col_values(1)
    close.reverse()
    close.pop()
    print("导入收盘价:", close)
Пример #14
0
# 先算出柱状图高度占比,下面有,得出间隔增量是25
bar1=Bar('餐饮类标签排名',title_top="0%")
bar2=Bar('景点类标签排名',title_top="25%")
bar3=Bar('娱乐类标签排名',title_top="50%")
bar4=Bar('购物类标签排名',title_top="75%")
# is_splitline_show 显示X轴的标尺线
# xaxis_rotate 未知
# legend_top 图例的顶部位置(可以用百分比)
# legend_pos 以控制图例的x轴位置,可以用百分比
# 图例的名字不同,则柱状图的颜色不同
bar1.add('餐饮游记',df1['城市'],df1['餐饮游记'],is_splitline_show=True,xaxis_rotate=30,legend_top="0%")
bar2.add('景点游记',df2['城市'],df2['景点游记'],is_splitline_show=True,xaxis_rotate=30,legend_top="25%")
bar3.add('娱乐游记',df3['城市'],df3['娱乐游记'],is_splitline_show=True,xaxis_rotate=30,legend_top="50%")
bar4.add('购物游记',df4['城市'],df4['购物游记'],is_splitline_show=True,xaxis_rotate=30,legend_top="75%")

grid=Grid(width=1280,height=700)
# grid_top grid组件离容器顶部距离
# grid_bottom grid组件离容器底部距离
# 也支持grid_left grid_right
# 100-(80+5)=15 容器的高度占比
grid.add(bar1,grid_top="5%",grid_bottom="80%")
# 四个柱状图高度占比:4*15=60
# 中间隔占比:100-60-5-5(第一5和最后5)=30,30/3=10
# 则间隔增量是:10(间隔占比)+15(柱状图高度占比)=25
grid.add(bar2,grid_top="30%",grid_bottom="55%")
grid.add(bar3,grid_top="55%",grid_bottom="30%")
grid.add(bar4,grid_top="80%",grid_bottom="5%")
'''
# 布局如图
——————————————
5
Пример #15
0
#encoding:utf-8
# 作者:孙亚楠
# 日期:2020/3/21 0021 18:41
# 工具:PyCharm
# Python版本:3.7.3
#此python文件完成功能:
from pyecharts import Grid,Line,Bar
# //设置行名
columns = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
# //设置数据
data1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
data2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
# //设置折线图标题位置
line = Line("折线图","一年的降水量与蒸发量",title_top="45%")
line.add("降水量", columns, data1, is_label_show=True)
line.add("蒸发量", columns, data2, is_label_show=True)
grid = Grid()
# //设置柱状图的主标题与副标题
bar = Bar("柱状图", "一年的降水量与蒸发量")
# //添加柱状图的数据及配置项
bar.add("降水量", columns, data1, mark_line=["average"], mark_point=["max", "min"])
bar.add("蒸发量", columns, data2, mark_line=["average"], mark_point=["max", "min"])
# //设置两个图表的相对位置
grid.add(bar, grid_bottom="60%")
grid.add(line, grid_top="60%")
grid.render()
Пример #16
0
# 将持仓和cci重叠在一个图中
cci_overlap = Overlap()
cci_overlap.add(cci_line)
cci_overlap.add(bar)
cci_overlap.render()

# 画出K线图
price = [[open, close, lowest,
          highest] for open, close, lowest, highest in zip(
              data['open'], data['close'], data['low'], data['high'])]
kline = Kline("贵州茅台", title_pos='center')
kline.add('日线',
          x_axis=data['date'],
          y_axis=price,
          is_datazoom_show=True,
          is_xaxislabel_align=True,
          tooltip_tragger='axis',
          yaxis_pos='left',
          legend_top="20%",
          legend_orient='vertical',
          legend_pos='right',
          is_toolbox_show=True,
          tooltip_formatter=show_kline_data)

# 将cci折线图和K线图合并到一张图表中
grid = Grid()
grid.add(cci_overlap, grid_top="70%")
grid.add(kline, grid_bottom="40%")

grid.render()
Пример #17
0
df_fuwu=df.drop(df[df['服务']==0].index,inplace=False)
df_fuwu=df_fuwu.groupby(by='城市').agg({'服务':'mean'}).reset_index()
df_fuwu=df_fuwu.sort_values(by='服务',ascending=False)[0:20]
df_fuwu['服务']=df_fuwu['服务'].map(lambda x:round(x,2))

# 柱状图
bar1=Bar('小龙虾人气城市',title_top="10px",title_pos="5%")
bar2=Bar('人均消费排名',title_top="180px",title_pos="5%")
bar3=Bar('口味评分排名',title_top="350px",title_pos="5%")
bar4=Bar('环境评分排名',title_top="520px",title_pos="5%")
bar5=Bar('服务评分排名',title_top="690px",title_pos="5%")

# is_splitline_show 水平标线 xaxis_rotate 未知 legend_top 图例离页面顶部距离
bar1.add('点评',df_dianping['城市'],df_dianping['点评'],is_splitline_show=True,xaxis_rotate=30,legend_top="10px",legend_pos="50%")
bar2.add('人均消费',df_renjun['城市'],df_renjun['人均'],is_splitline_show=True,xaxis_rotate=30,legend_top="180px",legend_pos="50%")
bar3.add('评分',df_kouwei['城市'],df_kouwei['口味'],is_splitline_show=True,xaxis_rotate=30,legend_top="350px",legend_pos="50%")
bar4.add('评分',df_huanjing['城市'],df_huanjing['环境'],is_splitline_show=True,xaxis_rotate=30,legend_top="520px",legend_pos="50%")
bar5.add('评分',df_fuwu['城市'],df_fuwu['服务'],is_splitline_show=True,xaxis_rotate=30,legend_top="690px",legend_pos="50%")

grid = Grid(height=1200,width=1280)
# grid_bottom 图表底部离页面底部距离 grid_top 图表顶部离页面顶部距离
'''100%-(grid_bottom:80 + grid_top 5)=15%即为柱状图高的占比, 即4个图占60%空间,并留一些白''' 
'''先填出第一个图(80,5)与最后一个图(5,80)的位置, 然后用(80-5)/(4-1)=25为增量间距'''
# grid.add(bar1,grid_bottom="80%",grid_top="6%" ,grid_left="5%",grid_right="55%")
grid.add(bar1,grid_top="50px",grid_bottom="1050px")
grid.add(bar2,grid_top="220px",grid_bottom="880px")
grid.add(bar3,grid_top="390px",grid_bottom="710px")
grid.add(bar4,grid_top="560px",grid_bottom="540px")
grid.add(bar5,grid_top="730px",grid_bottom="370px")
grid.render('小龙虾.html')
Пример #18
0
def test_page_grid_timeline_overlap():
    # Grid
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%")
    bar.add("商家A", CLOTHES, v1, is_stack=True)
    bar.add("商家B", CLOTHES, v2, is_stack=True, legend_pos="80%")
    line = Line("折线图示例")
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
        legend_pos="20%",
    )
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
    scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")
    es = EffectScatter("动态散点图示例", title_top="50%")
    es.add(
        "es",
        [11, 11, 15, 13, 12, 13, 10],
        [1, -2, 2, 5, 3, 2, 0],
        effect_scale=6,
        legend_top="50%",
        legend_pos="20%",
    )

    grid = Grid()
    grid.add(bar, grid_bottom="60%", grid_left="60%")
    grid.add(line, grid_bottom="60%", grid_right="60%")
    grid.add(scatter, grid_top="60%", grid_left="60%")
    grid.add(es, grid_top="60%", grid_right="60%")

    # Timeline
    bar_1 = Bar("2012 年销量", "数据纯属虚构")
    bar_1.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_1.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_1.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])

    bar_2 = Bar("2013 年销量", "数据纯属虚构")
    bar_2.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_2.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_2.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])

    bar_3 = Bar("2014 年销量", "数据纯属虚构")
    bar_3.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_3.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_3.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])

    bar_4 = Bar("2015 年销量", "数据纯属虚构")
    bar_4.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_4.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_4.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])

    bar_5 = Bar("2016 年销量", "数据纯属虚构", height=720, width=1200)
    bar_5.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_5.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_5.add(
        "冬季",
        CLOTHES,
        [randint(10, 100) for _ in range(6)],
        is_legend_show=True,
    )

    timeline = Timeline(is_auto_play=True, timeline_bottom=0)
    timeline.add(bar_1, "2012 年")
    timeline.add(bar_2, "2013 年")
    timeline.add(bar_3, "2014 年")
    timeline.add(bar_4, "2015 年")
    timeline.add(bar_5, "2016 年")

    # Overlap
    attr = ["{}月".format(i) for i in range(1, 13)]
    v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
    v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
    v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]

    bar = Bar(height=720, width=1200)
    bar.add("蒸发量", attr, v1)
    bar.add("降水量", attr, v2, yaxis_formatter=" ml", yaxis_max=250)
    line = Line()
    line.add("平均温度", attr, v3, yaxis_formatter=" °C")

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line, yaxis_index=1, is_add_yaxis=True)

    page = Page()
    page.add(grid)
    page.add(timeline)
    page.add(overlap)
    page.render()
Пример #19
0
# 设置折线图x轴标签
attr = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
# 分别设置折线图的两条线
line.add("最高气温",
         attr, [11, 11, 15, 13, 12, 13, 10],
         mark_point=["max", "min"],
         mark_line=["average"])
line.add("最低气温",
         attr, [1, -2, 2, 5, 3, 2, 0],
         mark_point=["max", "min"],
         mark_line=["average"],
         legend_pos="20%")
# 准备饼图的标签
attr = ["机械", "曙光", "人艺", "冶金", "管理", "外语"]
# 准备饼图的数据
v1 = [11, 12, 13, 10, 10, 10]
# 设置饼图
pie = Pie("饼图", title_pos="55%")
# 设置属性
pie.add("",
        attr,
        v1,
        radius=[45, 65],
        center=[65, 50],
        legend_pos="80%",
        legend_orient="vertical")
grid = Grid()
grid.add(line, grid_right="55%")
grid.add(pie, grid_left="60%")
# 生成html,打开即可
grid.render()
Пример #20
0
def plot(df):
    kl = df.copy()
    kl['MID'] = (kl['HIGH'] + kl['LOW']) / 2
    kl['AG13'] = kl['MID'].rolling(window=13).mean()
    kl['AG8'] = kl['MID'].rolling(window=8).mean()
    kl['AG5'] = kl['MID'].rolling(window=5).mean()
    kl['SMA5'] = kl['MID'].rolling(window=5).mean()
    kl['SMA34'] = kl['MID'].rolling(window=34).mean()
    kl['AO'] = kl['SMA5'] - kl['SMA34']
    kl['AC'] = (kl['AO'] -
                kl['AO'].rolling(window=5).mean()).rolling(window=5).mean()
    kl = kl[20:]
    for i in range(2, len(kl['MID'])):
        kl.ix[i, 'AG13'] = (kl.ix[i - 1, 'AG13'] * 12 +
                            (kl.ix[i, 'HIGH'] + kl.ix[i, 'LOW']) / 2) / 13
        kl.ix[i, 'AG8'] = (kl.ix[i - 1, 'AG8'] * 7 +
                           (kl.ix[i, 'HIGH'] + kl.ix[i, 'LOW']) / 2) / 8
        kl.ix[i, 'AG5'] = (kl.ix[i - 1, 'AG5'] * 4 +
                           (kl.ix[i, 'HIGH'] + kl.ix[i, 'LOW']) / 2) / 5
    kl['AG13'] = kl['AG13'].shift(8)
    kl['AG8'] = kl['AG8'].shift(5)
    kl['AG5'] = kl['AG5'].shift(3)
    kl = kl.where(kl.notnull(), 0)
    kl['GTUP'] = abs(kl['AG13'] - kl['AG8'])
    kl['GTDOWN'] = abs(kl['AG8'] - kl['AG5'])
    kl['MUP'] = 0
    kl['MDOWN'] = 0
    markd = []
    for i in range(2, len(kl['MID']) - 2):
        if kl.ix[i, 'HIGH'] == max(kl.ix[i - 2, 'HIGH'], kl.ix[i - 1, 'HIGH'],
                                   kl.ix[i, 'HIGH'], kl.ix[i + 1, 'HIGH'],
                                   kl.ix[i + 2, 'HIGH']):
            #kl.ix[i,'MUP']=1
            markd.append({
                "coord": [kl.index[i], kl.ix[i, 'HIGH']],
                "name": "1"
            })
        if kl.ix[i, 'LOW'] == min(kl.ix[i - 2, 'LOW'], kl.ix[i - 1, 'LOW'],
                                  kl.ix[i, 'LOW'], kl.ix[i + 1, 'LOW'],
                                  kl.ix[i + 2, 'LOW']):
            markd.append({
                "coord": [kl.index[i], kl.ix[i, 'LOW']],
                "name": "2"
            })

    page = Page(page_title='AC')
    kline = Kline()
    kline.add('',
              list(kl.index), [
                  list(kl[['OPEN', 'CLOSE', 'LOW', 'HIGH']].iloc[i, ].values)
                  for i in range(len(kl))
              ],
              is_datazoom_show=True,
              datazoom_xaxis_index=[0, 1],
              datazoom_type="both",
              is_xaxislabel_align=True,
              tooltip_axispointer_type="cross",
              mark_point=markd,
              mark_point_symbol='circle',
              mark_point_symbolsize=10)
    line = Line(' ')
    line.add('JAW',
             list(kl.index),
             list(kl['AG13']),
             line_color=['#0000ff'],
             label_color=['#0000ff'])
    line.add('TEETH',
             list(kl.index),
             list(kl['AG8']),
             line_color=['#ff0000'],
             label_color=['#ff0000'])
    line.add('LIPS',
             list(kl.index),
             list(kl['AG5']),
             line_color=['#00ff00'],
             label_color=['#00ff00'])
    overlap1 = Overlap()
    overlap1.add(kline)
    overlap1.add(line)
    #gator
    # bar1 = Bar(' ')
    # bar2 = Bar(' ')
    # up = list(kl['GTUP'])
    # down = list(kl['GTDOWN'])
    # redup = []
    # greenup = []
    # reddown = []
    # greendown = []
    # for i in range(len(up)):
    # 	if (i == 0):
    # 		greenup.append(up[i])
    # 		redup.append(0)
    # 		greendown.append(-down[i])
    # 		reddown.append(0)
    # 		continue
    # 	if (up[i] > up[i - 1]):
    # 		greenup.append(up[i])
    # 		redup.append(0)
    # 	else:
    # 		greenup.append(0)
    # 		redup.append(up[i])
    # 	if (down[i] > down[i - 1]):
    # 		greendown.append(-down[i])
    # 		reddown.append(0)
    # 	else:
    # 		greendown.append(0)
    # 		reddown.append(-down[i])
    #
    # 	# bar.add('MACDhist',klt,macd[2].tolist(),is_datazoom_show=True,legend_top='65%')
    # bar1.add('GTREDUP', list(kl.index), redup, legend_top='65%', label_color=['#ff0000'])
    # bar2.add('GTREDDOWN', list(kl.index), reddown, legend_top='65%', label_color=['#00ff00'])
    # bar1.add('GTGREENUP', list(kl.index), greenup, legend_top='65%', label_color=['#ff0000'])
    # bar2.add('GTGREENDOWN', list(kl.index), greendown, legend_top='65%', label_color=['#00ff00'])
    bar1 = Bar(' ')
    bar2 = Bar(' ')
    ac = list(kl['AC'])
    acr = []
    acg = []
    for i in range(len(ac)):
        if (i == 0):
            acr.append(ac[i])
            acg.append(0)
            continue
        if ac[i] > ac[i - 1]:
            acr.append(0)
            acg.append(ac[i])
        else:
            acr.append(ac[i])
            acg.append(0)
    bar1.add('ACR',
             list(kl.index),
             acr,
             legend_top='65%',
             label_color=['#ff0000'])
    bar2.add('ACG',
             list(kl.index),
             acg,
             legend_top='65%',
             label_color=['#00ff00'])
    overlap2 = Overlap()
    overlap2.add(bar1)
    overlap2.add(bar2)
    grid = Grid(width=1920, height=950)
    grid.add(overlap1, grid_bottom='40%')
    grid.add(overlap2, grid_top='70%')
    # page.add(line)
    # page.add(overlap)
    page.add(grid)
    path = os.path.abspath('.')
    page.render(path + '\\plot\\AC.html')
Пример #21
0
line.add(
    "最低气温",
    attr,
    [1, -2, 2, 5, 3, 2, 0],
    mark_point=["max", "min"],
    mark_line=["average"],
    legend_pos="20%",
)
# ************************************************************************************
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")
# ************************************************************************************
es = EffectScatter("动态散点图示例", title_top="50%")
es.add(
    "es",
    [11, 11, 15, 13, 12, 13, 10],
    [1, -2, 2, 5, 3, 2, 0],
    effect_scale=6,
    legend_top="50%",
    legend_pos="20%",
)
# ************************************************************************************
grid = Grid(height=720, width=1500)
grid.add(bar, grid_bottom="60%", grid_left="60%")
grid.add(line, grid_bottom="60%", grid_right="60%")
grid.add(scatter, grid_top="60%", grid_left="60%")
grid.add(es, grid_top="60%", grid_right="60%")
grid.render(path='ht3.html')
Пример #22
0
bar = Bar("iPhone销售状况")
bar.add("iPhone销售额", years, ip_sales)
bar2 = Bar()
bar2.add("iPhone销量", years, ip_unit, bar_category_gap=25)
percent = ip_sales.astype('float') / net_sales.astype('float')
line = Line()
line.add("收入占比",
         years,
         percent,
         line_width=3,
         yaxis_margin=60,
         yaxis_pos='left')
ol = Overlap()
ol.add(bar)
ol.add(bar2, is_add_yaxis=True, yaxis_index=1)
ol.add(line, is_add_yaxis=True, yaxis_index=2)
grid = Grid()
grid.add(ol, grid_left="15%")
grid.render()

cn_sales = data.loc['国行'].values
bar = Bar("国行销售状况")
bar.add("国行", years, cn_sales)
percent = cn_sales.astype('float') / net_sales.astype('float')
line = Line()
line.add("国行占比", years, percent, line_width=3)
ol = Overlap()
ol.add(bar)
ol.add(line, is_add_yaxis=True, yaxis_index=1)
ol.render()
Пример #23
0
def test_grid_four_direction():
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%")
    bar.add("商家A", CLOTHES, v1, is_stack=True)
    bar.add("商家B", CLOTHES, v2, is_stack=True, legend_pos="80%")
    line = Line("折线图示例")
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
        legend_pos="20%",
    )
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
    scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")
    es = EffectScatter("动态散点图示例", title_top="50%")
    es.add(
        "es",
        [11, 11, 15, 13, 12, 13, 10],
        [1, -2, 2, 5, 3, 2, 0],
        effect_scale=6,
        legend_top="50%",
        legend_pos="20%",
    )

    grid = Grid()
    grid.add(bar, grid_bottom="60%", grid_left="60%")
    grid.add(line, grid_bottom="60%", grid_right="60%")
    grid.add(scatter, grid_top="60%", grid_left="60%")
    grid.add(es, grid_top="60%", grid_right="60%")
    grid.render()
Пример #24
0
from pyecharts import Bar,Grid
import pandas as pd

sheet0 = pd.read_excel("./data_resources/出差省合同_2018拓展落实项目统计_柱状图.xls")
people0 = sheet0["合同省"][0:10].values.tolist()

days0 = sheet0["合同成本(万元)"][0:10].values.tolist()
# days0 = sheet0["对数值(取2位)"][0:10].values.tolist()
bar0 = Bar('2018拓展落实项目统计合同额度',title_pos="10%")
# bar0.add('出差省',people0,days0,xaxis_rotate = 40, yaxis_name = '合同成本Log10(万元)',yaxis_name_pos = 'middle',yaxis_name_gap = 40,legend_pos="35%",label_text_size = 10, is_label_show = True,label_pos= 'inside')
bar0.add('省名称',people0,days0,xaxis_rotate = 40, yaxis_name = '合同成本(万元)',yaxis_name_pos = 'middle',yaxis_name_gap = 50,legend_pos="35%",label_text_size = 12, is_label_show = True)

# bar.render(path = 'D:\\示例1.jpeg')

# bar.render("./all_charts/"+"个人出差人天成本比(补)"+".html")


# sheet1 = pd.read_excel("./data_resources/1.3出差城市与合同城市费用比值.xls")
# people1 = sheet1["合同市"][0:10].values.tolist()
# days1 = sheet1["合同/出差"][0:10].values.tolist()
# bar1 = Bar('出差城市与合同城市费用比值',title_pos="55%")
# bar1.add('合同市',people1,days1,xaxis_rotate = 40, yaxis_name = '成本比例(%)',yaxis_name_pos = 'middle',yaxis_name_gap = 40,legend_pos="80%",label_text_size = 8, is_label_show = True, label_pos= 'inside',mark_point = ['max'])
# # bar.render(path = 'D:\\示例1.jpeg')

grid = Grid(width=850)
grid.add(bar0, grid_right="10%")
# grid.add(bar0)
# # grid.render("./all_charts/"+"各组出差天数费用0.xls"+".html")
# grid.add(bar1, grid_left="50%")
grid.render("./all_charts/"+"1.2合同_2018"+".html")
Пример #25
0
def create_charts():
    page = Page()

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", height=800, width=WIDTH)
    bar.add("商家A", attr, v1, is_stack=True)
    bar.add("商家B", attr, v2, is_stack=True)
    line = Line("折线图示例", title_top="50%")
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温",
             attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"],
             mark_line=["average"])
    line.add("最低气温",
             attr, [1, -2, 2, 5, 3, 2, 0],
             mark_point=["max", "min"],
             mark_line=["average"],
             legend_top="50%")
    chart = Grid()
    chart.add(bar, grid_bottom="60%")
    chart.add(line, grid_top="60%")
    page.add(chart)

    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    scatter = Scatter("散点图示例", width=WIDTH, title_pos="55%")
    scatter.add("scatter", v1, v2, legend_pos="70%")
    es = EffectScatter("动态散点图示例")
    es.add("effectScatter", [11, 11, 15, 13, 12, 13, 10],
           [1, -2, 2, 5, 3, 2, 0],
           effect_scale=6,
           legend_pos="20%")
    chart = Grid()
    chart.add(scatter, grid_left="60%")
    chart.add(es, grid_right="60%")
    page.add(chart)

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", height=740, width=WIDTH, title_pos="65%")
    bar.add("商家A", attr, v1, is_stack=True)
    bar.add("商家B", attr, v2, is_stack=True, legend_pos="80%")
    line = Line("折线图示例")
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温",
             attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"],
             mark_line=["average"])
    line.add("最低气温",
             attr, [1, -2, 2, 5, 3, 2, 0],
             mark_point=["max", "min"],
             mark_line=["average"],
             legend_pos="20%")
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
    scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")
    es = EffectScatter("动态散点图示例", title_top="50%")
    es.add("es", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0],
           effect_scale=6,
           legend_top="50%",
           legend_pos="20%")
    chart = Grid()
    chart.add(bar, grid_bottom="60%", grid_left="60%")
    chart.add(line, grid_bottom="60%", grid_right="60%")
    chart.add(scatter, grid_top="60%", grid_left="60%")
    chart.add(es, grid_top="60%", grid_right="60%")
    page.add(chart)

    line = Line("折线图示例", width=WIDTH)
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温",
             attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"],
             mark_line=["average"])
    line.add("最低气温",
             attr, [1, -2, 2, 5, 3, 2, 0],
             mark_point=["max", "min"],
             mark_line=["average"],
             legend_pos="20%")
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图示例", title_pos="55%")
    pie.add("",
            attr,
            v1,
            radius=[45, 65],
            center=[70, 50],
            legend_pos="85%",
            legend_orient='vertical')
    chart = Grid()
    chart.add(line, grid_right="55%")
    chart.add(pie, grid_left="60%")
    page.add(chart)

    line = Line("折线图示例", width=WIDTH)
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温",
             attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"],
             mark_line=["average"])
    line.add("最低气温",
             attr, [1, -2, 2, 5, 3, 2, 0],
             mark_point=["max", "min"],
             mark_line=["average"],
             legend_pos="20%")
    v1 = [[2320.26, 2320.26, 2287.3,
           2362.94], [2300, 2291.3, 2288.26, 2308.38],
          [2295.35, 2346.5, 2295.35, 2345.92],
          [2347.22, 2358.98, 2337.35, 2363.8],
          [2360.75, 2382.48, 2347.89, 2383.76],
          [2383.43, 2385.42, 2371.23, 2391.82],
          [2377.41, 2419.02, 2369.57, 2421.15],
          [2425.92, 2428.15, 2417.58,
           2440.38], [2411, 2433.13, 2403.3, 2437.42],
          [2432.68, 2334.48, 2427.7, 2441.73],
          [2430.69, 2418.53, 2394.22, 2433.89],
          [2416.62, 2432.4, 2414.4, 2443.03],
          [2441.91, 2421.56, 2418.43, 2444.8],
          [2420.26, 2382.91, 2373.53, 2427.07],
          [2383.49, 2397.18, 2370.61, 2397.94],
          [2378.82, 2325.95, 2309.17, 2378.82],
          [2322.94, 2314.16, 2308.76, 2330.88],
          [2320.62, 2325.82, 2315.01, 2338.78],
          [2313.74, 2293.34, 2289.89, 2340.71],
          [2297.77, 2313.22, 2292.03, 2324.63],
          [2322.32, 2365.59, 2308.92, 2366.16],
          [2364.54, 2359.51, 2330.86, 2369.65],
          [2332.08, 2273.4, 2259.25, 2333.54],
          [2274.81, 2326.31, 2270.1, 2328.14],
          [2333.61, 2347.18, 2321.6, 2351.44],
          [2340.44, 2324.29, 2304.27, 2352.02],
          [2326.42, 2318.61, 2314.59, 2333.67],
          [2314.68, 2310.59, 2296.58, 2320.96],
          [2309.16, 2286.6, 2264.83, 2333.29],
          [2282.17, 2263.97, 2253.25, 2286.33],
          [2255.77, 2270.28, 2253.31, 2276.22]]
    kline = Kline("K 线图示例", title_pos="60%")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              v1,
              legend_pos="80%")
    chart = Grid()
    chart.add(line, grid_right="60%")
    chart.add(kline, grid_left="55%")
    page.add(chart)

    data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)]
    heatmap = HeatMap("热力图示例", width=WIDTH, height=700)
    heatmap.add("热力图直角坐标系",
                X_TIME,
                Y_WEEK,
                data,
                is_visualmap=True,
                visual_top="45%",
                visual_text_color="#000",
                visual_orient='horizontal')
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", title_top="52%")
    bar.add("商家A", attr, v1, is_stack=True)
    bar.add("商家B", attr, v2, is_stack=True, legend_top="50%")
    chart = Grid()
    chart.add(heatmap, grid_bottom="60%")
    chart.add(bar, grid_top="60%")
    page.add(chart)

    line = Line("折线图示例", width=WIDTH, height=700)
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温",
             attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"],
             mark_line=["average"])
    line.add("最低气温",
             attr, [1, -2, 2, 5, 3, 2, 0],
             mark_point=["max", "min"],
             legend_top="50%",
             mark_line=["average"],
             is_datazoom_show=True,
             datazoom_xaxis_index=[0, 1])

    v1 = [[2320.26, 2320.26, 2287.3,
           2362.94], [2300, 2291.3, 2288.26, 2308.38],
          [2295.35, 2346.5, 2295.35, 2345.92],
          [2347.22, 2358.98, 2337.35, 2363.8],
          [2360.75, 2382.48, 2347.89, 2383.76],
          [2383.43, 2385.42, 2371.23, 2391.82],
          [2377.41, 2419.02, 2369.57, 2421.15],
          [2425.92, 2428.15, 2417.58,
           2440.38], [2411, 2433.13, 2403.3, 2437.42],
          [2432.68, 2334.48, 2427.7, 2441.73],
          [2430.69, 2418.53, 2394.22, 2433.89],
          [2416.62, 2432.4, 2414.4, 2443.03],
          [2441.91, 2421.56, 2418.43, 2444.8],
          [2420.26, 2382.91, 2373.53, 2427.07],
          [2383.49, 2397.18, 2370.61, 2397.94],
          [2378.82, 2325.95, 2309.17, 2378.82],
          [2322.94, 2314.16, 2308.76, 2330.88],
          [2320.62, 2325.82, 2315.01, 2338.78],
          [2313.74, 2293.34, 2289.89, 2340.71],
          [2297.77, 2313.22, 2292.03, 2324.63],
          [2322.32, 2365.59, 2308.92, 2366.16],
          [2364.54, 2359.51, 2330.86, 2369.65],
          [2332.08, 2273.4, 2259.25, 2333.54],
          [2274.81, 2326.31, 2270.1, 2328.14],
          [2333.61, 2347.18, 2321.6, 2351.44],
          [2340.44, 2324.29, 2304.27, 2352.02],
          [2326.42, 2318.61, 2314.59, 2333.67],
          [2314.68, 2310.59, 2296.58, 2320.96],
          [2309.16, 2286.6, 2264.83, 2333.29],
          [2282.17, 2263.97, 2253.25, 2286.33],
          [2255.77, 2270.28, 2253.31, 2276.22]]
    kline = Kline("K 线图示例", title_top="50%")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              v1,
              is_datazoom_show=True)

    chart = Grid()
    chart.add(line, grid_top="60%")
    chart.add(kline, grid_bottom="60%")
    page.add(chart)

    attr = ['{}天'.format(i) for i in range(1, 31)]
    line_top = Line("折线图示例", width=WIDTH, height=700)
    line_top.add("最高气温",
                 attr, [random.randint(20, 100) for i in range(30)],
                 mark_point=["max", "min"],
                 mark_line=["average"],
                 legend_pos='38%')
    line_bottom = Line()
    line_bottom.add("最低气温",
                    attr, [random.randint(20, 100) for i in range(30)],
                    mark_point=["max", "min"],
                    mark_line=["average"],
                    is_yaxis_inverse=True,
                    xaxis_pos='top')
    chart = Grid()
    chart.add(line_top, grid_bottom='60%')
    chart.add(line_bottom, grid_top='50%')
    page.add(chart)

    attr = ["{}月".format(i) for i in range(1, 13)]
    v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
    v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
    v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
    bar = Bar("Overlap+Grid 示例", title_pos="40%", width=1100, height=600)
    bar.add("蒸发量", attr, v1)
    bar.add("降水量",
            attr,
            v2,
            yaxis_formatter=" ml",
            yaxis_max=250,
            legend_pos="85%",
            legend_orient="vertical",
            legend_top="45%")
    line = Line()
    line.add("平均温度", attr, v3, yaxis_formatter=" °C")
    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line, is_add_yaxis=True, yaxis_index=1)

    chart = Grid()
    chart.add(overlap, grid_right='20%')
    page.add(chart)

    return page
Пример #26
0
    def render(self):
        bar1, bar2, bar3 = self.get_data()
        grid = Grid(height=800)
        grid.add(bar1, grid_bottom="75%")
        grid.add(bar2, grid_bottom="37.5%", grid_top="37.5%")
        grid.add(bar3, grid_top="75%")
        grid.render('城市分类标签.html')

        self.city_base.sort_values('total_city_yj',
                                   ascending=False,
                                   inplace=True)
        attr = self.city_base['city_name'][0:10]
        v1 = self.city_base['total_city_yj'][0:10]
        bar = Bar("游记总数量TOP10")
        bar.add("游记总数", attr, v1, is_stack=True)
        bar.render('游记总数量TOP10.html')

        self.city_food.sort_values('food_count', ascending=False, inplace=True)
        attr_food = self.city_food['food'][0:15]
        # print(attr_food)
        v1_food = self.city_food['food_count'][0:15]
        bar_food = Bar('热门食物排名')
        bar_food.add('热门食物',
                     attr_food,
                     v1_food,
                     is_stack=True,
                     interval=0,
                     xaxis_rotate=30,
                     yaxix_min=4.2,
                     is_splitline_show=False)
        bar_food.render('热门食物.html')

        self.city_jd.sort_values('jd_count', ascending=False, inplace=True)
        attr_f = self.city_jd['jd'][0:15]
        v1_f = self.city_jd['jd_count'][0:15]
        bar_f = Bar('热门景点排名')
        bar_f.add('热门景点',
                  attr_f,
                  v1_f,
                  is_stack=True,
                  interval=0,
                  xaxis_rotate=30,
                  yaxix_min=4.2,
                  is_splitline_show=False)
        bar_f.render('热门景点.html')

        # 按照各个城市游记数量获得全国旅行目的地热力图
        # pycharts中的Geo绘制中国地图,在图中显示各个地区的旅游热度
        data = [(self.city_base['city_name'][i],
                 self.city_base['total_city_yj'][i])
                for i in range(0, self.city_base.shape[0])]
        geo = Geo('全国城市旅游热力图',
                  title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color='#404a59')
        while True:
            try:
                attr, value = geo.cast(data)
                geo.add("",
                        attr,
                        value,
                        visual_range=[0, 15000],
                        visual_text_color="#fff",
                        symbol_size=15,
                        is_visualmap=True,
                        is_roam=False)
            except ValueError as e:
                e = str(e)
                e = e.split("No coordinate is specified for ")[1]  # 获取不支持的城市名
                for i in range(0, len(data)):
                    if e in data[i]:
                        data.pop(i)
                        break
            else:
                break
        geo.render('蚂蜂窝游记热力图.html')


# if __name__=='__main__':
#     object=MaFengWoData()
#     object.view_data()
Пример #27
0
def test_grid_2():

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%")
    bar.add("商家A", attr, v1, is_stack=True)
    bar.add("商家B", attr, v2, is_stack=True, legend_pos="80%")
    line = Line("折线图示例")
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温",
             attr, [11, 11, 15, 13, 12, 13, 10],
             mark_point=["max", "min"],
             mark_line=["average"])
    line.add("最低气温",
             attr, [1, -2, 2, 5, 3, 2, 0],
             mark_point=["max", "min"],
             mark_line=["average"],
             legend_pos="20%")
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
    scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")
    es = EffectScatter("动态散点图示例", title_top="50%")
    es.add("es", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0],
           effect_scale=6,
           legend_top="50%",
           legend_pos="20%")

    grid = Grid()
    grid.add(bar, grid_bottom="60%", grid_left="60%")
    grid.add(line, grid_bottom="60%", grid_right="60%")
    grid.add(scatter, grid_top="60%", grid_left="60%")
    grid.add(es, grid_top="60%", grid_right="60%")
    grid.render()
Пример #28
0
    [2430.69, 2418.53, 2394.22, 2433.89],
    [2416.62, 2432.4, 2414.4, 2443.03],
    [2441.91, 2421.56, 2418.43, 2444.8],
    [2420.26, 2382.91, 2373.53, 2427.07],
    [2383.49, 2397.18, 2370.61, 2397.94],
    [2378.82, 2325.95, 2309.17, 2378.82],
    [2322.94, 2314.16, 2308.76, 2330.88],
    [2320.62, 2325.82, 2315.01, 2338.78],
    [2313.74, 2293.34, 2289.89, 2340.71],
    [2297.77, 2313.22, 2292.03, 2324.63],
    [2322.32, 2365.59, 2308.92, 2366.16],
    [2364.54, 2359.51, 2330.86, 2369.65],
    [2332.08, 2273.4, 2259.25, 2333.54],
    [2274.81, 2326.31, 2270.1, 2328.14],
    [2333.61, 2347.18, 2321.6, 2351.44],
    [2340.44, 2324.29, 2304.27, 2352.02],
    [2326.42, 2318.61, 2314.59, 2333.67],
    [2314.68, 2310.59, 2296.58, 2320.96],
    [2309.16, 2286.6, 2264.83, 2333.29],
    [2282.17, 2263.97, 2253.25, 2286.33],
    [2255.77, 2270.28, 2253.31, 2276.22],
]
kline = Kline('k线图示例', title_pos='60%')
kline.add('日k', ['2018/12/{}'.format(i + 1) for i in range(31)],
          v1,
          legend_pos='80%')

grid = Grid(width=1200)
grid.add(line, grid_right='60%')
grid.add(kline, grid_left='55%')
grid.render()
Пример #29
0
    def kline_echarts(self, code=None):

        def kline_formater(param):
            return param.name + ':' + vars(param)

        """plot the market_data"""
        if code is None:
            path_name = '.' + os.sep + 'QA_' + self.type + \
                '_codepackage_' + self.if_fq + '.html'
            kline = Kline('CodePackage_' + self.if_fq + '_' + self.type,
                          width=1360, height=700, page_title='QUANTAXIS')

            bar = Bar()
            data_splits = self.splits()

            for ds in data_splits:
                data = []
                axis = []
                if ds.type[-3:] == 'day':
                    datetime = np.array(ds.date.map(str))
                else:
                    datetime = np.array(ds.datetime.map(str))
                ohlc = np.array(
                    ds.data.loc[:, ['open', 'close', 'low', 'high']])

                kline.add(ds.code[0], datetime, ohlc, mark_point=[
                          "max", "min"], is_datazoom_show=True, datazoom_orient='horizontal')
            return kline

        else:
            data = []
            axis = []
            ds = self.select_code(code)
            data = []
            #axis = []
            if self.type[-3:] == 'day':
                datetime = np.array(ds.date.map(str))
            else:
                datetime = np.array(ds.datetime.map(str))

            ohlc = np.array(ds.data.loc[:, ['open', 'close', 'low', 'high']])
            vol = np.array(ds.volume)
            kline = Kline('{}__{}__{}'.format(code, self.if_fq, self.type),
                          width=1360, height=700, page_title='QUANTAXIS')
            bar = Bar()
            kline.add(self.code, datetime, ohlc,
                      mark_point=["max", "min"],
                      # is_label_show=True,
                      is_datazoom_show=True,
                      is_xaxis_show=False,
                      # is_toolbox_show=True,
                      tooltip_formatter='{b}:{c}',  # kline_formater,
                      # is_more_utils=True,
                      datazoom_orient='horizontal')

            bar.add(self.code, datetime, vol,
                    is_datazoom_show=True,
                    datazoom_xaxis_index=[0, 1])

            grid = Grid(width=1360, height=700, page_title='QUANTAXIS')
            grid.add(bar, grid_top="80%")
            grid.add(kline, grid_bottom="30%")
            return grid
Пример #30
0
    mark_line=["average"],
)
line.add(
    "最低气温",
    attr,
    [1, -2, 2, 5, 3, 2, 0],
    mark_point=["max", "min"],
    mark_line=["average"],
    legend_pos="20%",
)
v1 = [5, 20, 36, 10, 75, 90]
v2 = [10, 25, 8, 60, 20, 80]
scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")
es = EffectScatter("动态散点图示例", title_top="50%")
es.add(
    "es",
    [11, 11, 15, 13, 12, 13, 10],
    [1, -2, 2, 5, 3, 2, 0],
    effect_scale=6,
    legend_top="50%",
    legend_pos="20%",
)

grid = Grid()
grid.add(bar, grid_bottom="60%", grid_left="60%")
grid.add(line, grid_bottom="60%", grid_right="60%")
grid.add(scatter, grid_top="60%", grid_left="60%")
grid.add(es, grid_top="60%", grid_right="60%")
grid.render(path="demo.base64", delay=3)