Exemplo n.º 1
0
def loc_and_mean_age(info):
    grouped = group(info, ['cityChn'])
    tidy = grouped['age']
    tidy_com = tidy.agg(['mean', 'count'])
    tidy_com.reset_index(inplace=True)
    tidy_com['mean'] = round(tidy_com['mean'], 2)

    attr = tidy_com['cityChn']
    num = tidy_com['count']
    aver = tidy_com['mean']

    line = Line("小姐姐-平均年龄")
    line.add("年龄",
             attr,
             aver,
             is_stack=True,
             xaxis_rotate=30,
             mark_point=['max', 'min'],
             yaxis_min=26,
             is_splitline_show=False)

    bar = Bar("小姐姐-城区分布")
    bar.add("单位:人",
            attr,
            num,
            mark_point=['max'],
            mark_line=['average'],
            xaxis_rotate=30,
            yaxis_min=0)

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line, yaxis_index=1, is_add_yaxis=True)
    overlap.render("北京百合小姐姐平均年龄与分布.html")
Exemplo n.º 2
0
def avg():
    df = pd.read_csv('maoyan2.csv', error_bad_lines=False)
    df.round(2)
    # 根据日期统计各天的平均值,并保留两位小数
    date_score_avg = df.groupby('date')['score'].mean().round(2)*2
    # 根据评分数据生成柱状图

    bar = Bar('评分走势图', '数据来源:不正经程序员-采集自猫眼',
              title_pos='center', width=1500, height=600)
    # line = Line()
    # line.add('', attr, value)
    bar.add('', date_score_avg.index, date_score_avg.values, is_visualmap=False, visual_range=[0, 3500], visual_text_color='#fff', is_more_utils=True,
            is_label_show=True, xaxis_interval=0, xaxis_rotate=30, mark_line=["average"])
    overlap = Overlap()
    overlap.add(bar)
    # overlap.add(line)
    overlap.show_config()
    overlap.render(
        'picture\评分走势图.html')
        
    # 根据日期统计各天的平均值,并保留两位小数
    date_positive_prob_avg = df.groupby('date')['positive_prob'].mean().round(2)
    bar = Bar('评论情感指数走势图', '数据来源:不正经程序员-采集自猫眼',
              title_pos='center', width=1500, height=600)
    # line = Line()
    # line.add('', attr, value)
    bar.add('', date_positive_prob_avg.index, date_positive_prob_avg.values, is_visualmap=False, visual_range=[0, 3500], visual_text_color='#fff', is_more_utils=True,
            is_label_show=True, xaxis_interval=0, xaxis_rotate=30, mark_line=["average"])
    overlap = Overlap()
    overlap.add(bar)
    # overlap.add(line)
    overlap.show_config()
    overlap.render(
        'picture\评论情感指数走势图.html')
def forecastPlot(foreData, target, localPath):
    """
    :param ismn_data: DataFrame. Merged dataset of ISMN
    :return: html file stored in paht './plot/ismn_ts'
    """
    # create a new folder: plot/ismn_ts
    path = '../{}/predictionPlot'.format(localPath)
    if not os.path.exists(path):
        os.makedirs(path)
    foreData = foreData.copy()
    foreData['timeStamp'] = pd.to_datetime(foreData['timeStamp'])

    for station in foreData.station.unique():
        line = Line("forecast of soil mosture at %i cm" % target, station)
        overlap = Overlap(width=1200, height=500)
        dataset = foreData[foreData.station == station]
        dataset.index = dataset.timeStamp

        fore_columns = list(dataset.filter(regex='fore|actual').columns)
        for forecastVar in fore_columns:
            x = dataset.index
            y = list(dataset.loc[:, [forecastVar]].values.reshape(-1))
            line.add(forecastVar, x, y, is_datazoom_show=True)

        overlap.add(line)
        overlap.render(path=path +
                       '/{0}_forecast_{1}cm.html'.format(station, target))
Exemplo n.º 4
0
def generate_score_tabale():
    city_main = city_com.sort_values('count', ascending=False)[0:20]
    attr = city_main['city']
    v1 = city_main['count']
    v2 = city_main['mean']
    line = Line("主要城市平均评分")
    line.add("主要城市平均评分",
             attr,
             v2,
             is_stack=True,
             xaxis_rotate=50,
             yaxis_min=4.0,
             mark_point=['min', 'max'],
             xaxis_interval=0,
             line_color='lightblue',
             line_width=4,
             mark_point_textcolor='yellow',
             mark_point_color='lightblue',
             is_splitline_show=False)

    bar = Bar("主要城市评论数及评分")
    bar.add("主要城市评论数",
            attr,
            v1,
            is_stack=True,
            xaxis_rotate=50,
            yaxis_min=0,
            xaxis_interval=0,
            is_splitline_show=False)
    overlap = Overlap()
    # 默认不新增 x y 轴,并且 x y 轴的索引都为 0
    overlap.add(bar)
    overlap.add(line, yaxis_index=1, is_add_yaxis=True)
    overlap.render('resources/city_score.html')
Exemplo n.º 5
0
def xuqiu_diqu_mon(conn, width, height, mon):
    sql_xuqiu_diqu = "select name,count,mj from kanban_xuqiu_diqu where year(date_sub(create_date,interval 1 month))='%s'" \
                     "and month(date_sub(create_date,interval 1 month))='%s' order by mj desc"%(str(mon)[:4],str(mon)[-2:])
    data_xuqiu_diqu = pd.read_sql(sql_xuqiu_diqu, conn)

    xuqiu_diqu_name = list(data_xuqiu_diqu.iloc[:, 0])
    xuqiu_diqu_mj = list(data_xuqiu_diqu.iloc[:, 2])
    xuqiu_diqu_count = list(data_xuqiu_diqu.iloc[:, 1])

    xuqiu_diqu_title = str(mon)[:4] + '年' + str(mon)[-2:] + '月土流网土地需求区域分布'
    xuqiu_diqu_bar = Bar(xuqiu_diqu_title)
    xuqiu_diqu_bar.add("面积(亩)",
                       xuqiu_diqu_name,
                       xuqiu_diqu_mj,
                       xaxis_interval=0,
                       xaxis_rotate=90)
    xuqiu_diqu_line = Line()
    xuqiu_diqu_line.add("宗数",
                        xuqiu_diqu_name,
                        xuqiu_diqu_count,
                        xaxis_interval=0,
                        xaxis_rotate=90)

    xuqiu_diqu_overlap = Overlap(height=height, width=width)
    xuqiu_diqu_overlap.add(xuqiu_diqu_bar)
    xuqiu_diqu_overlap.add(xuqiu_diqu_line, yaxis_index=1, is_add_yaxis=True)
    xuqiu_diqu_overlap.render()

    return xuqiu_diqu_overlap
Exemplo n.º 6
0
def plot_days_to_trend(video_df, save_filename):
    """
    使用 pyecharts 统计视频发布后上榜的天数
    :param
            - video_df:
            - save_filename:
    """
    video_df['diff'] = (video_df['trending_date'] - video_df['publish_time']).dt.days
    days_df = video_df['diff'].value_counts()

    # 观察视频发布后2个月的情况
    days_df = days_df[(days_df.index >= 0) & (days_df.index <= 60)]
    days_df = days_df.sort_index()

    bar = Bar('视频发布后2个月的情况')
    bar.add(
        '柱状图', days_df.index.tolist(), days_df.values.tolist(),
        is_datazoom_show=True,  # 启用数据缩放功能
        datazoom_range=[0, 50]  # 百分比范围
    )

    line = Line()
    line.add('折线图', days_df.index.tolist(), days_df.values.tolist())

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line)
    overlap.render(os.path.join(config.output_path, save_filename))
Exemplo n.º 7
0
def assets_curve(dates, sum):
    xs = dates
    ys = sum
    xs_date = [x.date() for x in xs]

    line = Line("盈利走势图")
    line.add("盈利",
             xs_date,
             sum,
             is_smooth=True,
             mark_line=["min", "max", "average"],
             mark_point=[
                 'min', 'max', 'average', {
                     "coord": [xs_date[-1], ys[-1]],
                     "name": "now"
                 }
             ],
             is_datazoom_show=True,
             xaxis_name="时间",
             yaxis_name="元",
             tooltip_trigger="axis")

    overlap = Overlap(width=1200, height=600)
    # 默认不新增 x y 轴,并且 x y 轴的索引都为 0
    overlap.add(line)
    overlap.render('profit.html')
def moneyflow_lgt(date_start, date_end, df, save_path_moneyflow_lgt):

    df = df.assign(hgt=df.hgt.apply(lambda x: round(x / 100, 2)))
    df = df.assign(sgt=df.sgt.apply(lambda x: round(x / 100, 2)))
    df = df.assign(
        north_money=df.north_money.apply(lambda x: round(x / 100, 2)))

    title = ' 资金流向 - 陆股通(亿元)'
    subtitle = '    GZH: 摸鱼大佬'
    bar = Bar(title,
              subtitle,
              title_pos=0.1,
              subtitle_text_size=15,
              subtitle_color='#aa8')
    # bar.use_theme("macarons")
    bar.add("沪股通", df['trade_date'], df['hgt'], bar_category_gap='40%')
    bar.add("深股通", df['trade_date'], df['sgt'], bar_category_gap='40%')
    line = Line()
    line.add("北上资金",
             df['trade_date'],
             df['north_money'],
             mark_line=['average'],
             mark_point=['min', 'max'])
    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line, is_add_xaxis=False)  #是否新增一个 x 坐标轴,默认为 False
    render_path = save_path + 'moneyflow_lgt_' + date_end + '.png'
    # bar.render(path=render_path)
    overlap.render(path=render_path)
    # pic_zoom(render_path, save_path_tgbhotstock, 740)
    print('moneyflow_lgt done: ' + render_path)
    return render_path
Exemplo n.º 9
0
def example1(time_list, base_list, net_list, close_list):
    overlap = Overlap(
        width=1600,
        height=800,
    )
    line = Line()

    line.add(
        "BTC基准线",
        time_list,
        base_list,
        is_datazoom_show=True,
        is_datazoom_extra_show=True,
        is_legend_show=True,
        # is_label_show=True,
        is_more_utils=True,
        is_xaxislabel_align=True,
        is_yaxislabel_align=True,
        line_color="#7CFC00",
        line_width=3,
        tooltip_axispointer_type="cross",
        # mark_point=["max", "min"]
    )
    line.add(
        "净值",
        time_list,
        net_list,
        is_datazoom_show=True,
        is_datazoom_extra_show=True,
        is_legend_show=True,
        # is_label_show=True,
        is_more_utils=True,
        is_xaxislabel_align=True,
        is_yaxislabel_align=True,
        line_color="#00ff00",
        line_width=5,
        tooltip_axispointer_type="cross",
        # mark_point=["max", "min"]
    )
    line2 = Line()
    line2.add(
        "BTC价格",
        time_list,
        close_list,
        is_datazoom_show=True,
        is_datazoom_extra_show=True,
        is_legend_show=True,
        # is_label_show=True,
        is_more_utils=True,
        is_xaxislabel_align=True,
        is_yaxislabel_align=True,
        line_color="#696969",
        line_width=3,
        # mark_point=["max", "min"]
    )

    overlap.add(line)
    overlap.add(line2, is_add_yaxis=True, yaxis_index=1)
    overlap.render()
Exemplo n.º 10
0
def view(code, start_, end_, days):
    '''
    使用pyecharts展示数据
    :param code: 股票代码
    :param start_: 开始时间(包含)格式为'2018-01-01'
    :param end_: 结束时间(包含)格式为'2018-01-01'
    :param days: 设置求多少天内波动率
    :return:
    '''
    th = get_data_from_db(code, start_, end_)
    # 中间有数据缺失的情况,因为股票在工作日才会交易,非工作日的交易数据是缺失的,我们要填充上去
    l = len(th)
    start = th.iloc[0:1].index.tolist()[0]
    end = th.iloc[l - 1:l].index.tolist()[0]
    idx = pd.date_range(start=start, end=end)

    # 接着我们使用reindex函数将缺失数据补全
    # 数据补全的规则是,价格数据用前一个交易日的数据来填充,但是交易量需要填充为0
    data = th.reindex(idx)
    zvalues = data.loc[~(data.volume > 0)].loc[:, ['volume']]
    data.update(zvalues.fillna(0))

    # pad/ffill:用前一个非缺失值去填充该缺失值
    # backfill/bfill:用下一个非缺失值填充该缺失值
    data.fillna(method='ffill', inplace=True)  #

    # 根据分组索引来分组,days为分组时间长度
    group_index = gen_item_group_index(len(data), days)
    data['group_index'] = group_index
    group = data.groupby('group_index').agg({
        'volume': 'sum',
        'low': 'min',
        'high': _high_price
    })

    # 添加每个分组起始日期
    data_col = pd.DataFrame({'group_index': group_index, 'date': idx})
    group['date'] = data_col.groupby('group_index').agg('first')

    # 添加波动率
    group['ripples_radio'] = group.high / group.low
    attr = [str(x.strftime('%Y-%m-%d')) for x in group.date]
    v1 = [round(x, 2) for x in group.ripples_radio.tolist()]
    v2 = [round(x / 10000, 2) for x in group.volume.tolist()]

    bar = Bar(width=1200, height=600)
    bar.add("波动率", attr, v1)

    line = Line()
    line.add("成交量", attr, v2, yaxis_formatter=" 万手")

    overlap = Overlap()
    # 默认不新增 x y 轴,并且 x y 轴的索引都为 0
    overlap.add(bar)
    # 新增一个 y 轴,此时 y 轴的数量为 2,第二个 y 轴的索引为 1(索引从 0 开始),所以设置 yaxis_index = 1
    # 由于使用的是同一个 x 轴,所以 x 轴部分不用做出改变
    overlap.add(line, yaxis_index=1, is_add_yaxis=True)
    overlap.render('股票[{0}]{1}天波动率和成交量图.html'.format(code, days))
Exemplo n.º 11
0
def test_line_es():
    v1 = [5, 20, 36, 10, 10, 100]
    line = Line("line-EffectScatter 示例")
    line.add("", CLOTHES, v1, is_random=True)
    es = EffectScatter()
    es.add("", CLOTHES, v1, effect_scale=8)

    overlap = Overlap()
    overlap.add(line)
    overlap.add(es)
    overlap.render()
Exemplo n.º 12
0
def K_line(date, v1):
    kline = Kline("比特币历史价格")
    kline.add(
        "日K",
        date,
        v1,
        is_datazoom_show=True,
    )
    overlap = Overlap()
    overlap.add(kline)
    overlap.render()
Exemplo n.º 13
0
def test_line_es():
    v1 = [5, 20, 36, 10, 10, 100]
    line = Line("line-EffectScatter 示例")
    line.add("", CLOTHES, v1, is_random=True)
    es = EffectScatter()
    es.add("", CLOTHES, v1, effect_scale=8)

    overlap = Overlap()
    overlap.add(line)
    overlap.add(es)
    overlap.render()
Exemplo n.º 14
0
    def render_add(self, path="test1.html"):
        overlap = Overlap(
            width=1600,
            height=800,
        )
        # overlap.add(self.empty_line)
        overlap.add(self.kline)
        overlap.add(self.line, is_add_yaxis=True, yaxis_index=1)

        # overlap.add(self.line, yaxis_index=0)
        # overlap.add(self.kline, is_add_yaxis=True, yaxis_index=3)
        overlap.render(path=path)
Exemplo n.º 15
0
def Longgang(longgang,price,add):
    overlap=Overlap()
    print(longgang)
    attr=['布吉关', '布吉大芬', '布吉水径', '坂田', '布吉街', '布吉南岭', '丹竹头', '大运新城', '横岗', '龙岗双龙', '龙岗中心城', '龙岗宝荷', '坪地', '平湖']
    n1, n2, n3, n4, n5, n6,n7, n8, n9, n10, n11, n12,n13,n14 = [], [], [], [], [], [],[], [], [], [], [], [],[],[]
    for i in range(len(add)):
        if add[i] == longgang[0]:
            n1.append(price[i])
        if add[i] == longgang[1]:
            n2.append(price[i])
        if add[i] == longgang[2]:
            n3.append(price[i])
        if add[i] == longgang[3]:
            n4.append(price[i])
        if add[i] == longgang[4]:
            n5.append(price[i])
        if add[i] == longgang[5]:
            n6.append(price[i])
        if add[i] == longgang[6]:
            n7.append(price[i])
        if add[i] == longgang[7]:
            n8.append(price[i])
        if add[i] == longgang[8]:
            n9.append(price[i])
        if add[i] == longgang[9]:
            n10.append(price[i])
        if add[i] == longgang[10]:
            n11.append(price[i])
        if add[i] == longgang[11]:
            n12.append(price[i])
        if add[i] == longgang[12]:
            n13.append(price[i])
        if add[i] == longgang[13]:
            n14.append(price[i])
    l = [len(n1), len(n2), len(n3), len(n4), len(n5), len(n6), len(n7),
         len(n8), len(n9), len(n10),len(n11),len(n12),len(n13),len(n14)]
    ave = [round(numpy.mean(n1), 2), round(numpy.mean(n2), 2), round(numpy.mean(n3), 2),
           round(numpy.mean(n4), 2), round(numpy.mean(n5), 2), round(numpy.mean(n6), 2),
           round(numpy.mean(n7), 2), round(numpy.mean(n8), 2), round(numpy.mean(n9), 2),
           round(numpy.mean(n10), 2),round(numpy.mean(n11), 2), round(numpy.mean(n12), 2), round(numpy.mean(n13), 2),round(numpy.mean(n14), 2)]
    bar = Bar("龙岗区房屋数量_均价分布图", "", title_pos="left", width=1200, height=600)
    bar.add("", attr, ave, is_visualmap=True, visual_text_color='#fff',
            is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45)
    overlap.add(bar)
    line = Line('龙岗区房屋数量_均价图', width=1200, height=600)
    line.add('数量', attr, l, is_stack=True, mark_point=['max', 'min'], line_color='lightblue',
             is_more_utils=True, visual_range=[0, 50])
    overlap.add(line, is_add_yaxis=True, yaxis_index=1)
    overlap.render('龙岗区房屋数量_均价折线图.html')
    pie = Pie('龙岗区房屋数量面积占比', title_pos='center', width=1200, height=600)
    pie.add("", attr, l, label_text_color=None, is_label_show=True, legend_orient='vertical',
            is_more_utils=True, legend_pos='left')
    pie.render('龙岗区房屋数量占比Pie.html')
Exemplo n.º 16
0
class Draw(object):
    def __init__(self, path, ispage=True):
        self.page = Page()
        self.overlap = Overlap()
        self.ispage = ispage
        self.path = path
        self.range_color = [
            "#313695",
            "#4575b4",
            "#74add1",
            "#abd9e9",
            "#e0f3f8",
            "#ffffbf",
            "#fee090",
            "#fdae61",
            "#f46d43",
            "#d73027",
            "#a50026",
        ]

    def add(self, name, xs, ys):
        line = Line(name)
        for k, v in ys.items():
            line.add(k,
                     xs,
                     v,
                     is_smooth=False,
                     is_datazoom_show=True,
                     yaxis_min=min(v))
        self.page.add(line)

    def add3d(self, name, data):
        surface3D = Scatter3D(name, width=1200, height=600)
        surface3D.add(
            "",
            data,
            is_visualmap=True,
            visual_range=[-1000, 4000],
            visual_range_color=self.range_color,
        )
        self.page.add(surface3D)

    def add2y(self, name, xs, ys, yaxis_index=0):
        line = Line(name)
        for k, v in ys.items():
            line.add(k, xs, v, is_smooth=False, is_datazoom_show=True)
        self.overlap.add(line, yaxis_index=yaxis_index, is_add_yaxis=True)

    def draw(self):
        if self.ispage:
            self.page.render(self.path)
        else:
            self.overlap.render(self.path)
Exemplo n.º 17
0
def test_overlap_bar_line():
    attr = ["A", "B", "C", "D", "E", "F"]
    v1 = [10, 20, 30, 40, 50, 60]
    v2 = [38, 28, 58, 48, 78, 68]
    bar = Bar("Line-Bar 示例")
    bar.add("bar", attr, v1)
    line = Line()
    line.add("line", attr, v2)

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line)
    overlap.render()
Exemplo n.º 18
0
def test_overlap_bar_line():
    attr = ['A', 'B', 'C', 'D', 'E', 'F']
    v1 = [10, 20, 30, 40, 50, 60]
    v2 = [38, 28, 58, 48, 78, 68]
    bar = Bar("Line - Bar 示例")
    bar.add("bar", attr, v1)
    line = Line()
    line.add("line", attr, v2)

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line)
    overlap.render()
Exemplo n.º 19
0
def histogram(title, attr_list, value_list):
    bar = Bar(title)
    bar.add("关键词",
            attr_list,
            value_list,
            is_stack=True,
            xaxis_rotate=30,
            yaxix_min=4.2,
            xaxis_interval=0,
            is_splitline_show=False)
    overlap = Overlap()
    overlap.add(bar)
    overlap.render(f'{title}.html')
Exemplo n.º 20
0
def test_overlap_bar_line():
    attr = ['A', 'B', 'C', 'D', 'E', 'F']
    v1 = [10, 20, 30, 40, 50, 60]
    v2 = [38, 28, 58, 48, 78, 68]
    bar = Bar("Line-Bar 示例")
    bar.add("bar", attr, v1)
    line = Line()
    line.add("line", attr, v2)

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line)
    overlap.render()
Exemplo n.º 21
0
def test_overlap_bar_line():
    attr = ["A", "B", "C", "D", "E", "F"]
    v1 = [10, 20, 30, 40, 50, 60]
    v2 = [38, 28, 58, 48, 78, 68]
    bar = Bar("Line-Bar 示例")
    bar.add("bar", attr, v1)
    line = Line()
    line.add("line", attr, v2)

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line)
    overlap.render()
Exemplo n.º 22
0
    def dataGet(self):
        """获取行情"""
        data = self.data
        #print "data1111=", data
        #data.sort_values('date', inplace=True)
        ochl = data[['openPrice', 'lastPrice', 'hightPrice', 'lowPrice']]
        ochl_tolist = [ochl.ix[i].tolist() for i in range(len(ochl))]
        close_df = data['lastPrice']
        sma_N1 = talib.SMA(np.array(close_df), self.N1)
        sma_N2 = talib.SMA(np.array(close_df), self.N2)
        date_df = data.index
        kline = Candlestick()
        # datazoom_orient='vertical'  dataZoom效果加到纵坐标上
        kline.add(self.title,
                  date_df,
                  ochl_tolist,
                  mark_point=['max', 'min'],
                  is_datazoom_show=True,
                  mark_point_symbolsize=80,
                  mark_line_valuedim=['highest', 'lowest'])

        line = Line()
        line.add(u'{}日均线'.format(self.N1),
                 date_df,
                 sma_N1,
                 is_fill=False,
                 line_opacity=0.8,
                 is_smooth=True,
                 line_color='b')
        line.add(u'{}日均线'.format(self.N2),
                 date_df,
                 sma_N2,
                 is_fill=False,
                 line_opacity=0.8,
                 is_smooth=True,
                 line_color='g')

        overlap = Overlap(page_title=self.title,
                          width=self.overWidth,
                          height=self.overHeight)
        overlap.add(kline)
        overlap.add(line)
        KLine_path = r'KLine.html'
        overlap.render(KLine_path)
        # 自动打开HTML
        #self.driver = webdriver.Firefox()
        #self.driver.get(KLine_path)


#if __name__ == '__main__':
#PyechartsKLine()
Exemplo n.º 23
0
def moneyflow_a_stock_all(date_start, date_end, save_path_moneyflow_ggt=''):
    # '000001.SH', '上证指数'
    # '399001.SZ', '深证成指'
    # '399006.SZ', '创业板指'
    # '399005.SZ', '中小板指'
    df1 = pro.index_daily(
        ts_code='000001.SH',
        start_date=date_start,
        end_date=date_last_trade_day).sort_index(ascending=False)
    df2 = pro.index_daily(
        ts_code='399001.SZ',
        start_date=date_start,
        end_date=date_last_trade_day).sort_index(ascending=False)
    # df3 = pro.index_daily(ts_code='399006.SZ', start_date=date_start, end_date=date_last_trade_day).sort_index(ascending=False)
    # df4 = pro.index_daily(ts_code='399005.SZ', start_date=date_start, end_date=date_last_trade_day).sort_index(ascending=False)
    # df5 = pro.index_daily(ts_code='399300.SZ', start_date=date_start, end_date=date_last_trade_day).sort_index(ascending=False)

    df0 = pd.DataFrame()
    df0['amount'] = df1['amount'] + df2['amount']
    df0['trade_date'] = df1['trade_date']

    df0 = df0.assign(amount=df0.amount.apply(lambda x: round(x / 100000, 0)))
    df1 = df1.assign(amount=df1.amount.apply(lambda x: round(x / 100000, 0)))
    df2 = df2.assign(amount=df2.amount.apply(lambda x: round(x / 100000, 0)))
    print(df0)

    title = ' 盘面资金 - A股(亿元)'
    subtitle = '    GZH: 摸鱼大佬'
    bar = Bar(title,
              subtitle,
              title_pos=0.1,
              subtitle_text_size=15,
              subtitle_color='#aa8')
    # bar.use_theme("macarons")
    bar.add("上证", df1['trade_date'], df1['amount'], bar_category_gap='40%')
    bar.add("深证", df2['trade_date'], df2['amount'], bar_category_gap='40%')
    line = Line()
    line.add("全市场",
             df0['trade_date'],
             df0['amount'],
             mark_line=['average'],
             mark_point=['min', 'max'])
    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line, is_add_xaxis=False)  #是否新增一个 x 坐标轴,默认为 False
    render_path = save_path + 'moneyflow_a_stock_all_' + date_end + '.png'
    # bar.render(path=render_path)
    overlap.render(path=render_path)
    # pic_zoom(render_path, save_path_tgbhotstock, 740)
    print('moneyflow_ggt done: ' + render_path)
    return render_path
Exemplo n.º 24
0
def draw(a, b, x_list, y_list):
    """
    画图
    """

    s = Scatter('最小二乘法')
    s.add('散点', x_list, y_list)
    l = Line()
    l.add('y = {a} + {b}x'.format(a=a, b=b), [x_list[0], x_list[-1]],
          [a + (x_list[0] * b), a + (x_list[-1] * b)])
    o = Overlap()
    o.add(s)
    o.add(l)
    o.render('最小二乘法.html')
Exemplo n.º 25
0
def test_overlap_kline_line():
    import random

    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],
    ]
    attr = ["2017/7/{}".format(i + 1) for i in range(31)]
    kline = Kline("Kline-Line 示例")
    kline.add("日K", attr, v1)
    line_1 = Line()
    line_1.add("line-1", attr, [random.randint(2400, 2500) for _ in range(31)])
    line_2 = Line()
    line_2.add("line-2", attr, [random.randint(2400, 2500) for _ in range(31)])

    overlap = Overlap()
    overlap.add(kline)
    overlap.add(line_1)
    overlap.add(line_2)
    overlap.render()
Exemplo n.º 26
0
def test_overlap_kline_line():
    import random

    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],
    ]
    attr = ["2017/7/{}".format(i + 1) for i in range(31)]
    kline = Kline("Kline-Line 示例")
    kline.add("日K", attr, v1)
    line_1 = Line()
    line_1.add("line-1", attr, [random.randint(2400, 2500) for _ in range(31)])
    line_2 = Line()
    line_2.add("line-2", attr, [random.randint(2400, 2500) for _ in range(31)])

    overlap = Overlap()
    overlap.add(kline)
    overlap.add(line_1)
    overlap.add(line_2)
    overlap.render()
Exemplo n.º 27
0
 def plot_line(self, title, keys, values, **kwargs):
     if 'compos' in kwargs.keys(
     ) and kwargs['compos'] and 'base_line' in kwargs.keys():
         chart = Overlap('风险敞口和价格', width=1360, height=700)
         base_chart = kwargs['base_line']
         line = Line()
         line.add('', keys, values, **kwargs)
         chart.add(base_chart)
         chart.add(line, yaxis_index=1, is_add_yaxis=True)
         self.page.add(chart)
     else:
         chart = Line(title, title_pos='left')
         chart.add('', keys, values, **kwargs)
         chart.render('{}.html'.format(title))
     return chart
Exemplo n.º 28
0
def test_custom_0():

    attr = ['A', 'B', 'C', 'D', 'E', 'F']
    v1 = [10, 20, 30, 40, 50, 60]
    v2 = [15, 25, 35, 45, 55, 65]
    v3 = [38, 28, 58, 48, 78, 68]
    bar = Bar("Line - Bar 示例")
    bar.add("bar", attr, v1)
    line = Line()
    line.add("line", v2, v3)

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line)
    overlap.render()
Exemplo n.º 29
0
def size_price(size,price):
    #page=Page()
    overlap=Overlap()
    #print(size)
    k=[]
    attr=['0-30','30-60','60-90','90-120','120-150','150及以上']
    for i in range(len(size)):
        size[i]=float(size[i][:-2])
    n1,n2,n3,n4,n5,n6=[],[],[],[],[],[]
    for i in range(len(size)):
        if size[i]<=30:
            #print(size[i])
            n1.append(price[i])
        #n1.append(size[i])
        if 30<size[i]<=60:
            n2.append(price[i])
        #n2.append(size[i])
        if 60< size[i] <= 90:
            n3.append(price[i])
        # n3.append(size[i])
        if 90<size[i]<=120:
            n4.append(price[i])
        #n4.append(size[i])
        if 120<size[i]<=150:
            n5.append(price[i])
        #n5.append(size[i])
        if 150<size[i]:
            n6.append(price[i])
    #n6.append(size[i])
    l=[len(n1),len(n2),len(n3),len(n4),len(n5),len(n6)]
    ave=[numpy.mean(n1),numpy.mean(n2),numpy.mean(n3),numpy.mean(n4),numpy.mean(n5),numpy.mean(n6)]
    bar = Bar("房屋面积_数量价位分布图", "", title_pos="left", width=1200, height=600)
    bar.add("", attr,ave, is_visualmap=True, visual_text_color='#fff',
            is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45)
    overlap.add(bar)
    #page.add(bar)
    #bar.render('房屋面积_数量bar.html')
    line = Line('房屋面积_均价图', width=1200, height=600)
    line.add('数量', attr,l, is_stack=True, mark_point=['max', 'min'],line_color='lightblue',
             is_more_utils=True, visual_range=[0, 50])
    #page.add(line)
    overlap.add(line,is_add_yaxis=True,yaxis_index=1)
    #line.render('房屋面积_均价折线图.html')
    overlap.render('房屋面积_数量_均价折线图.html')
    pie=Pie('面积占比', title_pos='center', width=1200, height=600)
    pie.add("", attr, l, label_text_color=None, is_label_show=True, legend_orient='vertical',
            is_more_utils=True, legend_pos='left')
    pie.render('面积占比Pie.html')
Exemplo n.º 30
0
def name_trend(name, data, gender=['M','F'], year=1920, dodge = 500):
    if isinstance(gender, str):
        name_data = data[(data['Name'] == name)&(data['Gender']==gender)&(data['Year']>=year)]
        attr = list(name_data['Year'].values)
        bar = Bar(name)
        bar.add("", attr, list(name_data['Count'].values), mark_line=["average"], mark_point=["max", "min"],
               legend_text_size=18,xaxis_label_textsize=18,yaxis_label_textsize=18)
        line = Line()
        line.add("", attr, list(name_data['Count'].values + dodge))
        
    else:
        name_data = data[(data['Name'] == name)&(data['Year']>=year)]
        attr = list(range(year, 2018))
        v1 = name_data[name_data['Gender']==gender[0]].Count.values
        v2 = name_data[name_data['Gender']==gender[1]].Count.values
        bar = Bar(name)
        bar.add("男", attr, list(v1), legend_text_size=18,xaxis_label_textsize=18,yaxis_label_textsize=18)
        bar.add("女", attr, list(v2), legend_text_size=18,xaxis_label_textsize=18,yaxis_label_textsize=18)
        line = Line()
        line.add("", attr, list(v1 + dodge))
        line.add("", attr, list(v2 + dodge))
    
    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line)
    return overlap.render(str(name)+str(gender)+str(dodge)+'.html')
Exemplo n.º 31
0
def overlap(data):
    # line
    line = Line('star compare', width=1000, height=400)
    line.add("dashen star line", data['name'], data['star'], xaxis_rotate=45)
    movie_star = data['movie_star']/10
    line.add("movie star line", data['name'], movie_star, xaxis_rotate=45)
    # bar
    bar = Bar("star compare", width=1000, height=400)
    bar.add("dashen star bar", data['name'], data['star'], xaxis_rotate=45, is_label_show=True, is_datazoom_show=True)
    movie_star = data['movie_star'] / 10
    bar.add("movie star bar", data['name'], movie_star, xaxis_rotate=45, is_label_show=True, is_datazoom_show=True)
    # overlap
    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line)
    overlap.render()
Exemplo n.º 32
0
    def render_add(self, path="test.html"):

        overlap = Overlap(
            width=1600,
            height=800,
        )

        overlap.add(self.kline)
        overlap.add(self.line)
        overlap.add(self.line_long_win)
        overlap.add(self.line_long_loss)
        overlap.add(self.line_short_win)
        overlap.add(self.line_short_loss)

        # overlap.add(self.kline2, is_add_yaxis=True, yaxis_index=1)
        overlap.render(path)
Exemplo n.º 33
0
    def create_line_and_column_chart(self, city_data_frame):
        city_main = city_data_frame.sort_values('count', ascending=False)[0:20]
        # print(city_main)
        attr = city_main['user_loc']
        v1 = city_main['count']
        v2 = city_main['mean']
        # print(attr,v1,v2)
        line = Line("主要城市评分")
        line.add(
            "城市",
            attr,
            v2,
            is_stack=True,
            xaxis_rotate=30,
            yaxix_min=4.2,
            mark_point=['min', 'max'],  # 对最大最小值进行标记
            xaxis_interval=0,
            line_color='#2196F3',
            line_width=4,
            mark_point_textcolor='#eeeeee',
            mark_point_color='#2196F3',
            is_splitline_show=False)

        bar = Bar("主要城市评论数")
        bar.add("城市",
                attr,
                v1,
                is_stack=True,
                xaxis_rotate=30,
                yaxix_min=4.2,
                xaxis_interval=0,
                mark_point=['min', 'max'],
                is_splitline_show=False)

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

        file_path = ''
        if self.movie.platform == 0:
            file_path = './' + self.movie.movie_name + '/【豆瓣】《' + self.movie.movie_name + '》主要城市评论数_平均分.html'
        elif self.movie.platform == 1:
            file_path = './' + self.movie.movie_name + '/【猫眼】《' + self.movie.movie_name + '》主要城市评论数_平均分.html'
        else:
            file_path = './' + self.movie.movie_name + '/【豆瓣+猫眼】《' + self.movie.movie_name + '》主要城市评论数_平均分.html'
        overlap.render(file_path)
        print('折线 + 柱形图创建完毕')
Exemplo n.º 34
0
def test_overlap_two_yaxis():
    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(width=1200, height=600)
    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)
    overlap.render()
Exemplo n.º 35
0
def test_overlap_es_scatter():
    v1 = [10, 20, 30, 40, 50, 60]
    v2 = [30, 30, 30, 30, 30, 30]
    v3 = [50, 50, 50, 50, 50, 50]
    v4 = [10, 10, 10, 10, 10, 10]
    es = EffectScatter("Scatter-EffectScatter 示例")
    es.add("es", v1, v2)
    scatter = Scatter()
    scatter.add("scatter", v1, v3)
    es_1 = EffectScatter()
    es_1.add("es_1", v1, v4, symbol='pin', effect_scale=5)

    overlap = Overlap()
    overlap.add(es)
    overlap.add(scatter)
    overlap.add(es_1)
    overlap.render()
Exemplo n.º 36
0
def test_overlap_two_yaxis():
    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(width=1200, height=600)
    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)
    overlap.render()