首頁>技術>

先給大家展現給不一樣得東西看看。

導包
# 匯入options配置項from pyecharts import options as opts# 匯入柱狀圖,時間軸from pyecharts.charts import Bar,Timeline# 匯入Faker隨機生成標籤from pyecharts.faker import Faker# 使用random隨機生成數值import random
首先我們隨機生成x軸資料
phone=Faker.phones
開頭展示的柱狀圖熟悉麼?
tl = Timeline()# 寫一個時間軸函式def timeline_bar() -> Timeline:    for i in range(2015, 2020):        data1=random.sample(range(0, 100), 7)         data2=random.sample(range(0, 100), 7)        bar=Bar()        bar.add_xaxis(phone)        bar.add_yaxis('A店',data1)        bar.add_yaxis('B店',data2)        bar.set_global_opts(title_opts=opts.TitleOpts(title='手機{}年銷售量'.format(i),subtitle='A、B兩門店對比'))        tl.add(bar, "{}年".format(i))    return tltimeline_bar().render_notebook()
新增資料標籤和輔助線之後的時間軸展示
tl = Timeline()def timeline_bar() -> Timeline:    for i in range(2015, 2020):        data1=random.sample(range(10, 100), 7)         data2=random.sample(range(10, 100), 7)        bar=(Bar()             .add_xaxis(phone)             .add_yaxis('A店',data1)             .add_yaxis('B店',data2)             .set_global_opts(title_opts=opts.TitleOpts(title='手機{}年銷售量'.format(i),subtitle='A、B兩門店對比'),                                                       legend_opts=opts.LegendOpts(is_show=True)                     )             .set_series_opts(label_opts=opts.LabelOpts(is_show=True),                              markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max',name='最大值')]),                              markline_opts=opts.MarkLineOpts(data=[opts.MarkPointItem(type_='min',name='最小值')])                    )    )        tl.add(bar, "{}年".format(i))    return tl  timeline_bar().render_notebook()

效果

變換之後得效果展示
tl = Timeline()def timeline_bar() -> Timeline:    for i in range(2015, 2020):        data1=random.sample(range(10, 100), 7)         data2=random.sample(range(10, 100), 7)        bar=(Bar()             .add_xaxis(phone)             .add_yaxis('A店',data1,stack="stack1", category_gap="50%")             .add_yaxis('B店',data2, stack="stack1", category_gap="50%")             .set_global_opts(title_opts=opts.TitleOpts(title='手機{}年銷售量'.format(i),subtitle='A、B兩門店對比'),                              legend_opts=opts.LegendOpts(is_show=True),                                          )             .set_series_opts(label_opts=opts.LabelOpts(is_show=True),                              markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max',name='最大值')]),                              markline_opts=opts.MarkLineOpts(data=[opts.MarkPointItem(type_='min',name='最小值')])                       )             .reversal_axis()    )        tl.add(bar, "{}年".format(i))    return tl  timeline_bar().render_notebook()
效果再來看看堆積柱狀圖的樣子!
tl = Timeline()def timeline_bar() -> Timeline:    for i in range(2015, 2020):        data1=random.sample(range(10, 100), 7)         data2=random.sample(range(10, 100), 7)        bar=(Bar()             .add_xaxis(phone)             .add_yaxis('A店',data1,stack="stack1", category_gap="50%")             .add_yaxis('B店',data2, stack="stack1", category_gap="50%")             .set_global_opts(title_opts=opts.TitleOpts(title='手機{}年銷售量'.format(i),subtitle='A、B兩門店對比'),                              legend_opts=opts.LegendOpts(is_show=True),                                          )             .set_series_opts(label_opts=opts.LabelOpts(is_show=True),                              markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_='max',name='最大值')]),                              markline_opts=opts.MarkLineOpts(data=[opts.MarkPointItem(type_='min',name='最小值')])                    )    )        tl.add(bar, "{}年".format(i))    return tl  timeline_bar().render_notebook()
效果

給大家介紹一位新朋友!!!

# 匯入3D柱狀圖的包from pyecharts.charts import Bar3D# 隨機生成x.y.z軸資料phone=Faker.phonesdays =Faker.week_endata = [(i, j, random.randint(0,20)) for i in range(7) for j in range(7)]bar3d=Bar3D(init_opts=opts.InitOpts(width="1500px", height="500px"))bar3d.add(        series_name="",        data=data,        xaxis3d_opts=opts.Axis3DOpts(type_="category", data=phone),        yaxis3d_opts=opts.Axis3DOpts(type_="category", data=days),        zaxis3d_opts=opts.Axis3DOpts(type_="value"),    )bar3d.set_global_opts(        visualmap_opts=opts.VisualMapOpts(            max_=25        )    )bar3d.render_notebook()

細心地小夥伴今天可能已經發現了,我們的程式碼是用鏈式法寫的,這樣的簡便寫法大家嘗試一下

12
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 使用拓撲排序求解深度學習網路節點的前向傳播和反向傳播順序