欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用pyecharts1.7進(jìn)行簡(jiǎn)單的可視化大全

 更新時(shí)間:2020年05月17日 15:56:16   作者:theskylife  
這篇文章主要介紹了使用pyecharts1.7進(jìn)行簡(jiǎn)單的可視化大全,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

近期,又有接觸到pyecharts這個(gè)包的使用,后面發(fā)現(xiàn)這個(gè)曾經(jīng)好用的包發(fā)生了一些變化,為了方便大家的使用,這里整理如下:
繪圖風(fēng)格theme:默認(rèn)WHITE
LIGHT, DARK, WHITE, CHALK, ESSOS, INFOGRAPHIC, MACARONS, PURPLE_PASSION, ROMA, ROMANTIC, SHINE, VINTAGE, WALDEN, WESTEROS, WONDERLAND

1.柱狀圖繪制

1.1 最基礎(chǔ)的柱狀圖

from pyecharts.charts import Bar,Grid
from pyecharts import options as opts
from pyecharts.globals import ThemeType
import random
import numpy as np
# 準(zhǔn)備數(shù)據(jù)
name=["A","B","C","D"]
salery=[random.randint(3000,5000) for i in range(4)]
#繪圖
bar=Bar(init_opts = opts.InitOpts(width='600px',height='400px')) 
bar.add_xaxis(name)
bar.add_yaxis("salery",salery)
bar.set_global_opts(title_opts=opts.TitleOpts(title="收入情況"))
#僅在notebook中顯示
bar.render_notebook()
#在HTML中顯示
bar.render("收入情況")

效果圖:

1.2 稍微復(fù)雜的柱狀圖

為了減少代碼量,此處不再導(dǎo)入包。繪制收入和消費(fèi)情況,并使用新風(fēng)格,并添加副標(biāo)題,使用新版本的鏈?zhǔn)綄懛ā?/p>

#準(zhǔn)備數(shù)據(jù)
name=["A","B","C","D"]
salery=[random.randint(3000,5000) for i in range(4)]
cost=[random.randint(1000,2000) for i in range(4)]
#繪圖
bar=(
  Bar(init_opts = opts.InitOpts(width='600px',height='400px',theme=ThemeType.LIGHT))
  .add_xaxis(name)
  .add_yaxis("salery",salery)
  .add_yaxis("cost",cost)
  .set_global_opts(title_opts=opts.TitleOpts(title="收入及消費(fèi)情況",subtitle="隨機(jī)樣本"))
)
bar.render_notebook()

#效果圖:

1.3 堆疊式柱狀圖

使用堆疊式柱狀圖(部分堆疊),并自定義顏色,修改圖例的顯示位置,不顯示數(shù)字,改變背景顏色

#準(zhǔn)備數(shù)據(jù)
name=["A","B","C","D"]
salery=[random.randint(3000,5000) for i in range(4)]
cost=[random.randint(1000,2000) for i in range(4)]
#所在城市平均薪水
salery_ave=[random.randint(3000,4000) for i in range(4)]
colors=["#007892","#ff427f","#fc8210","#ffd8a6"]
#進(jìn)行繪圖
bar=(
  Bar(init_opts = opts.InitOpts(width='600px',height='400px',bg_color=colors[-1]))
  .add_xaxis(name)
  .add_yaxis("salery",salery,stack="stack_one")
  .add_yaxis("cost",cost,stack="stack_one")
  .add_yaxis("salery_ave",salery_ave)
  .set_colors(colors)
  .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
  .set_global_opts(title_opts=opts.TitleOpts(title="收入、消費(fèi)及其城市平均收入情況"),
          legend_opts=opts.LegendOpts(type_="scroll", pos_right="right", orient="vertical")
          )
)
bar.render_notebook()

效果展示:

1.3.1 調(diào)整標(biāo)題與圖的位置

grid=Grid()
# 分別調(diào)整上下左右的位置,參數(shù)為像素值或百分比
grid.add(bar,grid_opts=opts.GridOpts(pos_top="30%",pos_bottom="10%",pos_left="10%",pos_right="10%"))
grid.render_notebook()

效果演示

1.4 繪制簇狀圖

#準(zhǔn)備數(shù)據(jù)
name=["A","B","C","D"]
salery=[random.randint(3000,5000) for i in range(4)]
cost=[random.randint(1000,2000) for i in range(4)]
#所在城市平均薪水
salery_ave=[random.randint(3000,4000) for i in range(4)]
colors=["#007892","#ff427f","#fc8210","#ffd8a6"]
#進(jìn)行繪圖
bar=(
  Bar(init_opts = opts.InitOpts(width='600px',height='400px',bg_color=colors[-1]))
  .add_xaxis(name)
  .add_yaxis("salery",salery)
  .add_yaxis("salery_ave",salery_ave)
  .reversal_axis()
  .set_colors(colors)
  .set_series_opts(label_opts=opts.LabelOpts(position="right"))
  .set_global_opts(title_opts=opts.TitleOpts(title="收入、消費(fèi)及其城市平均收入情況"),
          legend_opts=opts.LegendOpts(type_="scroll", pos_right="right", orient="vertical")
          )
)
bar.render_notebook()

效果圖演示

1.5 數(shù)據(jù)量大時(shí)的顯示方法

#準(zhǔn)備數(shù)據(jù)
name=[chr(i) for i in range(65,85,1)]
salery=[random.randint(3000,5000) for i in range(20)]
#所在城市平均薪水
salery_ave=[random.randint(3000,4000) for i in range(20)]
colors=["#007892","#ff427f","#fc8210","#ffd8a6"]
#繪圖 修改 orient為vertical,可將滑動(dòng)按鈕移動(dòng)垂直方向
bar=(
  Bar(init_opts = opts.InitOpts(width='600px',height='400px',bg_color=colors[-1]))
  .add_xaxis(name)
  .add_yaxis("salery",salery)
  .add_yaxis("salery_ave",salery_ave)
  .set_colors(colors)
  .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
  .set_global_opts(title_opts=opts.TitleOpts(title="收入、消費(fèi)及其城市平均收入情況"),
          legend_opts=opts.LegendOpts(type_="scroll", pos_right="right", orient="vertical"),
          datazoom_opts=[opts.DataZoomOpts(type_="slider")]
          )
)
bar.render_notebook()

演示效果:

2.繪制散點(diǎn)圖

2.1 普通散點(diǎn)圖

import random
from pyecharts import options as opts
from pyecharts.charts import Scatter
from pyecharts.globals import ThemeType

#準(zhǔn)備數(shù)據(jù)
name=["A","B","C","D"]
salery=[random.randint(3000,5000) for i in range(4)]
cost=[random.randint(1000,2000) for i in range(4)]
#所在城市平均薪水
salery_ave=[random.randint(3000,4000) for i in range(4)]
colors=["#007892","#ff427f","#fc8210","#ffd8a6"]
#進(jìn)行繪圖
scatter=(Scatter(init_opts = opts.InitOpts(width='600px',height='400px',theme=ThemeType.DARK))
    .add_xaxis(name)
    .add_yaxis("salery",salery)
    .add_yaxis("cost",cost)
    .set_global_opts(title_opts=opts.TitleOpts(title="收入與消費(fèi)情況")))
scatter.render_notebook()

查看效果:

2.2 3D散點(diǎn)圖繪制

import random
from pyecharts import options as opts
from pyecharts.charts import Scatter3D
from pyecharts.faker import Faker


#準(zhǔn)備數(shù)據(jù)
data = [(random.randint(0,100),random.randint(0,100),random.randint(0,100)) for i in range(50)]
name=["長(zhǎng)","寬","高"]
#繪圖
scatter3D=Scatter3D(init_opts = opts.InitOpts(width='600px',height='400px')) #初始化
scatter3D.add(name,data,
     grid3d_opts=opts.Grid3DOpts(
     width=100, depth=100
    ))
scatter3D.set_global_opts(title_opts=opts.TitleOpts(title="散點(diǎn)圖"),
             visualmap_opts=opts.VisualMapOpts(
             range_color=Faker.visual_color #顏色映射 
             ))
scatter3D.render_notebook()

效果圖:

2.3 帶漣漪的散點(diǎn)圖

symbol的類型:
“pin”,“rect”,“roundRect”,“diamond”,“arrow”,“triangle”

import random
from pyecharts import options as opts
from pyecharts.charts import EffectScatter
from pyecharts.globals import ThemeType

#準(zhǔn)備數(shù)據(jù)
name=["A","B","C","D"]
salery=[random.randint(3000,5000) for i in range(4)]
cost=[random.randint(1000,2000) for i in range(4)]
#所在城市平均薪水
salery_ave=[random.randint(3000,4000) for i in range(4)]
colors=["#007892","#ff427f","#fc8210","#ffd8a6"]
#進(jìn)行繪圖
scatter=(EffectScatter(init_opts = opts.InitOpts(width='600px',height='400px',theme=ThemeType.DARK))
    .add_xaxis(name)
    .add_yaxis("salery",salery,symbol="pin",symbol_size=20,symbol_rotate=180)
    .add_yaxis("cost",cost,symbol="rect",symbol_size=20)
    .set_global_opts(title_opts=opts.TitleOpts(title="收入與消費(fèi)情況"),
            xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)), #添加網(wǎng)格
            yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True))
            )
    .set_series_opts(effect_opts=opts.EffectOpts(scale=3,period=2)) #調(diào)整漣漪的范圍和周期
    )
scatter.render_notebook()

效果圖如下:

到此這篇關(guān)于使用pyecharts1.7進(jìn)行簡(jiǎn)單的可視化大全的文章就介紹到這了,更多相關(guān)pyecharts1.7 可視化內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論