使用pyecharts1.7進(jìn)行簡(jiǎn)單的可視化大全
近期,又有接觸到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)文章希望大家以后多多支持腳本之家!
- 利用pyecharts讀取csv并進(jìn)行數(shù)據(jù)統(tǒng)計(jì)可視化的實(shí)現(xiàn)
- python使用pyecharts庫(kù)畫地圖數(shù)據(jù)可視化的實(shí)現(xiàn)
- Flask和pyecharts實(shí)現(xiàn)動(dòng)態(tài)數(shù)據(jù)可視化
- Python數(shù)據(jù)可視化處理庫(kù)PyEcharts柱狀圖,餅圖,線性圖,詞云圖常用實(shí)例詳解
- Python數(shù)據(jù)可視化 pyecharts實(shí)現(xiàn)各種統(tǒng)計(jì)圖表過(guò)程詳解
- 利用pyecharts實(shí)現(xiàn)地圖可視化的例子
- 如何利用Pyecharts可視化微信好友
- Python 數(shù)據(jù)可視化pyecharts的使用詳解
相關(guān)文章
Python如何基于selenium實(shí)現(xiàn)自動(dòng)登錄博客園
這篇文章主要介紹了Python如何基于selenium實(shí)現(xiàn)自動(dòng)登錄博客園,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12python機(jī)器學(xué)習(xí)理論與實(shí)戰(zhàn)(二)決策樹
這篇文章主要介紹了python機(jī)器學(xué)習(xí)理論與實(shí)戰(zhàn)第二篇,決策樹的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01python 經(jīng)緯度求兩點(diǎn)距離、三點(diǎn)面積操作
這篇文章主要介紹了python 經(jīng)緯度求兩點(diǎn)距離、三點(diǎn)面積操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06python實(shí)現(xiàn)凱撒密碼、凱撒加解密算法
這篇文章主要介紹了python語(yǔ)言編程實(shí)現(xiàn)凱撒密碼、凱撒加解密算法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06Python?OpenCV基于HSV的顏色分割實(shí)現(xiàn)示例
這篇文章主要為大家介紹了Python?OpenCV基于HSV的顏色分割實(shí)現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06python實(shí)現(xiàn)修改固定模式的字符串內(nèi)容操作示例
這篇文章主要介紹了python實(shí)現(xiàn)修改固定模式的字符串內(nèi)容操作,結(jié)合實(shí)例形式詳細(xì)分析了Python修改固定模式字符串原理、實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-12-12