如何利用pyecharts畫好看的餅狀圖
前言
使用的pyecharts是v1.0
這里需要注意,pyecharts0.5的版本和v1.0以上的版本完全不一樣,可以說是兩個(gè)包
該包能夠方便快捷的繪制圖形
餅狀圖
圓環(huán)
代碼:
from pyecharts.charts import Pie from pyecharts import options as opts from pyecharts.render import make_snapshot from snapshot_phantomjs import snapshot def getPie(data,name): ''' style like this https://gallery.pyecharts.org/#/Pie/pie_radius 樣式為 空心 的圓環(huán) :param data:字典 :param name:title :return: ''' c = ( Pie() .add( "", [list(z) for z in zip(data.keys(), data.values())], radius=["45%", "75%"],#直徑 center=["50%", "56%"],#中心位置 label_opts=opts.LabelOpts(is_show=False, position="center"),#is_show是否展示數(shù)值 ) .set_global_opts( title_opts=opts.TitleOpts(title=name, pos_top="13",pos_left="1%"),#標(biāo)題位置 legend_opts=opts.LegendOpts(orient="vertical", pos_top="25%", pos_left="8%"),#圖例位置 ) .set_series_opts(label_opts=opts.LabelOpts(formatter="size: vvxyksv9kd%"))#數(shù)值表現(xiàn)形式,這里是百分比 # .render("pie_radius.html") ) return c if __name__=="__main__": data = ########## name = ############# make_snapshot(snapshot, getPie(data,name).render(), name+".png")#無法直接存儲(chǔ),所以使用此方法進(jìn)行存儲(chǔ),將圖像繪制,保存在本地
效果展示
(此處是png,背景實(shí)際是純白背景)
圓餅
代碼
def getPie1(data,name): ''' style like this https://gallery.pyecharts.org/#/Pie/pie_radius 樣式為 空心 的圓環(huán) :param data: :param name: :return: ''' c = ( Pie() .add( "", [list(z) for z in zip(data.keys(), data.values())], center=["50%", "56%"], label_opts=opts.LabelOpts(is_show=False, position="center"), ) .set_global_opts( title_opts=opts.TitleOpts(title=name, pos_top="13",pos_left="1%"), legend_opts=opts.LegendOpts(orient="vertical", pos_top="25%", pos_left="8%"), ) .set_series_opts(label_opts=opts.LabelOpts(formatter="size: vvxyksv9kd%")) # .render("pie_radius.html") ) return c # 這里main函數(shù)省略,和上面的一樣
效果展示
附上pyecharts的官方手冊(cè):https://pyecharts.org/#/zh-cn/intro
總結(jié)
到此這篇關(guān)于如何利用pyecharts畫好看餅狀圖的文章就介紹到這了,更多相關(guān)pyecharts畫餅狀圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python的pyecharts繪制各種圖表詳細(xì)(附代碼)
- Python數(shù)據(jù)可視化 pyecharts實(shí)現(xiàn)各種統(tǒng)計(jì)圖表過程詳解
- python使用pyecharts庫畫地圖數(shù)據(jù)可視化的實(shí)現(xiàn)
- 使用pyecharts在jupyter notebook上繪圖
- Flask使用Pyecharts在單個(gè)頁面展示多個(gè)圖表的方法
- 利用 Flask 動(dòng)態(tài)展示 Pyecharts 圖表數(shù)據(jù)方法小結(jié)
- python pyecharts 實(shí)現(xiàn)一個(gè)文件繪制多張圖
- python實(shí)現(xiàn)Pyecharts實(shí)現(xiàn)動(dòng)態(tài)地圖(Map、Geo)
- 利用pyecharts實(shí)現(xiàn)地圖可視化的例子
- pyecharts繪制中國(guó)2020肺炎疫情地圖的實(shí)例代碼
相關(guān)文章
Python 處理數(shù)據(jù)的實(shí)例詳解
這篇文章主要介紹了Python 處理數(shù)據(jù)的實(shí)例詳解的相關(guān)資料,這里主要介紹Python 常用的基礎(chǔ)知識(shí)并附實(shí)例,需要的朋友可以參考下2017-08-08Django數(shù)據(jù)模型中on_delete使用詳解
這篇文章主要介紹了Django數(shù)據(jù)模型中on_delete使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11keras 實(shí)現(xiàn)輕量級(jí)網(wǎng)絡(luò)ShuffleNet教程
這篇文章主要介紹了keras 實(shí)現(xiàn)輕量級(jí)網(wǎng)絡(luò)ShuffleNet教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-06-06python實(shí)現(xiàn)音樂播放器 python實(shí)現(xiàn)花框音樂盒子
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)音樂播放器,實(shí)現(xiàn)花框音樂盒子,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02