Exemplo n.º 1
0
def get_viz(method, label, data):
    if method == 'bar':
        viz = charts.Bar()
        viz.add_xaxis(label)
        viz.add_yaxis('', data)
    elif method == 'pie':
        data = [list(d) for d in zip(label, data)]
        viz = charts.Pie()
        viz.add('', data)
    return viz
Exemplo n.º 2
0
 def draw_multi_bar(self):
     date = 0
     iccid_list = []
     x_data = [[0], [50], [100], [150], [200], [250], [300], [350], [400],
               [450], [500], [550], [600], [650], [700], [750], [800],
               [850], [900], [950], '>1G']
     v1 = [[8, 5, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
           [64, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3],
           [
               63, 11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
               1
           ],
           [
               197, 60, 26, 24, 17, 11, 14, 9, 6, 6, 6, 5, 6, 1, 5, 9, 4, 2,
               2, 0, 116
           ],
           [
               144, 52, 29, 17, 15, 11, 10, 6, 8, 3, 10, 8, 22, 17, 14, 10,
               10, 7, 10, 0, 159
           ],
           [
               1225, 507, 288, 192, 129, 90, 62, 71, 46, 28, 32, 29, 58, 43,
               25, 21, 30, 11, 12, 0, 242
           ],
           [
               416, 180, 146, 78, 49, 49, 46, 16, 23, 16, 13, 10, 15, 23,
               18, 11, 15, 11, 4, 0, 215
           ],
           [
               602, 244, 115, 83, 57, 37, 22, 35, 33, 27, 19, 13, 25, 22,
               10, 15, 17, 13, 8, 0, 288
           ]]
     bar = pyec.Bar()
     for i in range(201905, 201913):
         bar.add_xaxis(x_data)
         bar.add_yaxis(series_name=str(i), yaxis_data=v1[i - 201905])
         bar.overlap(bar)
     bar.render('../TotalData.html')
bar.add('软件工程师',
        attr,
        a3_list,
        mark_point=['max'],
        tooltip_trigger='axis',
        tooltip_axispointer_type='cross',
        bar_category_gap=45)  #追加最大值标记点、最小值标记点
bar.add('管理',
        attr,
        a4_list,
        mark_point=['max'],
        tooltip_trigger='axis',
        tooltip_axispointer_type='cross',
        bar_category_gap=45,
        is_label_show=True)  #追加最大值标记点、最小值标记点

bar.render(r"D:\BI大屏\统计学招聘\前五职位薪资对比柱状图.html")

# 用pyechart 1.5.11版的命令
#==============================================================================
import pyecharts.charts as pyec
import pyecharts.options as opts

bar = pyec.Bar()
# 添加标题
bar.set_global_opts(title_opts=opts.TitleOpts(title='2018-2019薪资比较图'))
bar.add_xaxis(attr)
bar.add_yaxis('2019', b)
bar.add_yaxis('2018', c)
bar.render(r"D:\BI大屏\图\薪资对比柱状图.html")
Exemplo n.º 4
0
import numpy as np
import re
import pandas as pd
from pyecharts import charts as chas
from pyecharts import options as opts

file_path = r'E:\爬虫pycharm\data\goods_detail\10231420_with_ad.xlsx'
data_df = pd.DataFrame(pd.read_excel(file_path))
data_df.dropna(subset=['sales_est'], inplace=True)
data_df.sort_values(by=['sales_est'], inplace=True, ascending=False)
data_bar = (chas.Bar().add_xaxis(data_df['ASIN'].tolist()).add_yaxis(
    "预测销量",
    data_df['sales_est'].tolist(),
    label_opts=opts.LabelOpts(is_show=False)).set_global_opts(
        title_opts=opts.TitleOpts(title='销量预测'),
        legend_opts=opts.LegendOpts(is_show=True),
        toolbox_opts=opts.ToolboxOpts(),
        datazoom_opts=opts.DataZoomOpts(),
    ))


def money_change(strr):
    money_ = None
    if strr:
        try:
            money_ = float(strr.replace(',', '').strip('$'))
        except:
            money_ = None
    if re.search(strr, '-'):
        try:
            strr_1, strr_2 = strr.split('-')
Exemplo n.º 5
0
def create_bar(x_list, col_name, y_list):
    bar = charts.Bar()
    bar.add_xaxis(x_list)
    bar.add_yaxis(col_name, y_list)
    bar.render("Main/Sources/bar.html")
Exemplo n.º 6
0
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 31 08:16:29 2019

@author: Administrator
"""

import pyecharts.charts as pyec

# 柱状图
x = ['甲','乙','丙']
y = [300,800,600]

bar = pyec.Bar()
bar.add_xaxis(x)
bar.add_yaxis(series_name = '公司A',yaxis_data = y)
# 保存
bar.render(r'D:\Python Spyder\数据可视化\My PyEcharts\柱状图.html')

#加一些配置选项
import pyecharts.options as opts
    # 添加标题
bar.set_global_opts(title_opts = opts.TitleOpts(title = '比较图'))
bar.render(r'D:\Python Spyder\数据可视化\My PyEcharts\柱状图2.html')

#增加一个数据系列
y1 = [1200,500,200]
bar.add_yaxis(series_name = '公司B',yaxis_data=y1) 
bar.render(r'D:\Python Spyder\数据可视化\My PyEcharts\柱状图3.html')

# 变成条形图
Exemplo n.º 7
0
'''
page = Page()  # 使用page则只需要最后page进行render即可

# 也可以采用如下的链式调用,  使用options配置项
xtick = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
ytickA = [5, 20, 36, 10, 75, 90]
ytickB = [15, 6, 45, 20, 35, 66]
# 在使用 Pandas&Numpy 时,请确保将数值类型转换为 python 原生的 int/float。
# 比如整数类型请确保为 int,而不是 numpy.int32
labelA = "商家A"
labelB = "商家B"
bar = (
    charts.Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))  # 使用主题
    .add_xaxis(xtick).add_yaxis(labelA, ytickA).add_yaxis(labelB, ytickB)
    # 设置title
    .set_global_opts(title_opts={
        'text': '主标题',
        'subtext': '副标题'
    }))
# bar.render('bar_echats.html')           # 渲染网页
# 渲染图片: snapshot-selenium
# make_snapshot(snapshot, bar.render('bar_echats.html'), "bar_echarts.jpeg")
page.add(bar)

begin = datetime.date(2018, 1, 1)
end = datetime.date(2019, 1, 1)
data = []
for i in range((end - begin).days):
    temp = [
        str(begin + datetime.timedelta(days=i)),
        random.randint(1000, 25000)
Exemplo n.º 8
0
def bar_chart_display_delay(request):
    category = ["类目{}".format(i) for i in range(0, 100)]
    red_bar = [
        0,
        -8.901463875624668,
        -17.025413764148556,
        -24.038196249566663,
        -29.66504684804471,
        -33.699527649688676,
        -36.00971978255796,
        -36.541005056170455,
        -35.31542466107655,
        -32.427752866005996,
        -28.038563739693934,
        -22.364693082297347,
        -15.667600860943732,
        -8.240217424060843,
        -0.3929067389459173,
        7.560799717904647,
        15.318054209871054,
        22.599523033552096,
        29.16065418543528,
        34.800927952557615,
        39.37074152590451,
        42.77569739999406,
        44.97819140223978,
        45.99632376477021,
        45.900279829731865,
        44.806440199911805,
        42.86957840395034,
        40.2735832137877,
        37.22119936652441,
        33.92331243435557,
        30.588309963978517,
        27.412031986865767,
        24.56878097935778,
        22.203796820272576,
        20.427519715115604,
        19.311867685884827,
        18.888649906111855,
        19.150128087782186,
        20.051630602288828,
        21.516023200879346,
        23.439750867099516,
        25.700091656548704,
        28.163208735293757,
        30.692553648214542,
        33.1571635093161,
        35.439407573791215,
        37.44177367693234,
        39.09234039030659,
        40.34865356244595,
        41.19981246258526,
        41.66666666666667,
        41.80012531240646,
        41.67768039516203,
        41.39834040182826,
        41.07625507973403,
        40.833382300579814,
        40.79160029175877,
        41.06470032034727,
        41.75070457358366,
        42.924940903672564,
        44.63427081999565,
        46.89281122872821,
        49.679416561286956,
        52.93709961387478,
        56.574470884754874,
        60.46917221906629,
        64.47317623531558,
        68.41972346252496,
        72.1315793340836,
        75.43021771943799,
        78.14548044723074,
        80.12522637371026,
        81.24447108408411,
        81.41353029256493,
        80.58471628367427,
        78.75719600392792,
        75.97969924353211,
        72.35086229880064,
        68.01710226438443,
        63.16803467673056,
        58.029567166714706,
        52.854918421647554,
        47.91391949819902,
        43.48104807503482,
        39.82272085822884,
        37.18442111754884,
        35.778264289169215,
        35.77160292258658,
        37.27724241244461,
        40.345781666728996,
        44.96051012913295,
        51.035187614675685,
        58.41491053964701,
        66.8801325453253,
        76.15376513468516,
        85.91114110149952,
        95.79248672571518,
        105.41742429574506,
        114.40092042993717,
        122.37001313784816,
    ]
    blue_bar = [
        -50,
        -47.18992898088751,
        -42.54426104547181,
        -36.290773900754886,
        -28.71517529663627,
        -20.146937097399626,
        -10.94374119697364,
        -1.4752538113770308,
        7.893046603320797,
        16.81528588241657,
        24.979206795219028,
        32.11821023962515,
        38.02096119056733,
        42.53821720798438,
        45.58667093073836,
        47.14973738101559,
        47.275355710354944,
        46.07100702178889,
        43.6962693226927,
        40.35333240268025,
        36.275975292575026,
        31.71756381888028,
        26.938653692729076,
        22.194784893913152,
        17.725026430574392,
        13.741778696752679,
        10.422266555457615,
        7.902063853319403,
        6.270884006107842,
        5.570756810898967,
        5.796594266992678,
        6.899033489892203,
        8.7893381290192,
        11.346045936704996,
        14.42297348773613,
        17.858132851517098,
        21.483081596548438,
        25.132218074866262,
        28.651548555679597,
        31.906490373810854,
        34.788333671419466,
        37.21906041552118,
        39.154309232933485,
        40.58437366457342,
        41.5332247510366,
        42.05565130942339,
        42.23270781895,
        42.165745792772285,
        41.969375711588256,
        41.76375960543808,
        41.66666666666667,
        41.7857343479728,
        42.21136481847887,
        43.01065209435119,
        44.22268037417866,
        45.855461823273586,
        47.88469584957917,
        50.25443606443524,
        52.879650371477126,
        55.650558977584225,
        58.43853958732492,
        61.10330341815434,
        63.500974294013034,
        65.49264961151306,
        66.95298925309743,
        67.77836838841961,
        67.89414332224722,
        67.26061575374229,
        65.87733853082335,
        63.785482681031894,
        61.068077697490004,
        57.84804048526095,
        54.284018163297375,
        50.564180830851214,
        46.89820707575337,
        43.50780217852947,
        40.616171775045245,
        38.4369379107128,
        37.16302649485318,
        36.95607267600796,
        37.93688225696513,
        40.17745279877072,
        43.694998595987045,
        48.44834150353593,
        54.33692802801367,
        61.20261650152743,
        68.83425165632042,
        76.97491319735354,
        85.33159602026458,
        93.58695857541488,
        101.4126683297632,
        108.48378461530217,
        114.49355390682695,
        119.16795429637915,
        122.27931702317058,
        123.65837448506679,
        123.20413594805603,
        120.89107255501017,
        116.7731992576505,
        110.98476877890735,
    ]

    c = pc.Bar(init_opts=opts.InitOpts(width="1300px", height="600px"))\
        .add_xaxis ( xaxis_data = category)\
        .add_yaxis(
        series_name = "bar" , yaxis_data = red_bar , label_opts = opts.LabelOpts ( is_show = False )
    ) \
        .add_yaxis(
        series_name="bar2" ,
        yaxis_data=blue_bar ,
        label_opts=opts.LabelOpts(is_show=False) ,
    )\
        .set_global_opts(
        title_opts=opts.TitleOpts(title="柱状图动画延迟") ,
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=False)) ,
        yaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_show=True) ,
            splitline_opts=opts.SplitLineOpts(is_show=True) ,
        ) ,
    )
    return HttpResponse(c.render_embed())
Exemplo n.º 9
0
def bar(request):
    c = (pc.Bar().add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]).add_yaxis(
        "商家A", [5, 20, 36, 10, 75, 90]).add_yaxis(
            "商家B", [15, 25, 16, 55, 48, 8]).set_global_opts(
                title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题")))
    return HttpResponse(c.render_embed())
Exemplo n.º 10
0
 def draw_dymatic_bar(self, x_data, y_data, name, title):
     bar = pyec.Bar()
     bar.add_xaxis(x_data)
     bar.add_yaxis(series_name=title, yaxis_data=y_data)
     bar.render('./TotalData' + name + '.html')