如何利用pyecharts畫好看的餅狀圖
前言
使用的pyecharts是v1.0
這里需要注意,pyecharts0.5的版本和v1.0以上的版本完全不一樣,可以說(shuō)是兩個(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: owyp7lc%"))#數(shù)值表現(xiàn)形式,這里是百分比
# .render("pie_radius.html")
)
return c
if __name__=="__main__":
data = ##########
name = #############
make_snapshot(snapshot, getPie(data,name).render(), name+".png")#無(wú)法直接存儲(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: ca7h8m2%"))
# .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ì)圖表過(guò)程詳解
- python使用pyecharts庫(kù)畫地圖數(shù)據(jù)可視化的實(shí)現(xiàn)
- 使用pyecharts在jupyter notebook上繪圖
- Flask使用Pyecharts在單個(gè)頁(yè)面展示多個(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關(guān)于抽獎(jiǎng)系統(tǒng)的思考與設(shè)計(jì)思路
這篇文章主要介紹了Python關(guān)于抽獎(jiǎng)系統(tǒng)的思考與設(shè)計(jì)思路,本文通過(guò)一些簡(jiǎn)單的例子來(lái)說(shuō)一說(shuō)抽獎(jiǎng)系統(tǒng)背后的邏輯,看看究竟是你運(yùn)氣不好還是系統(tǒng)邏輯在作怪,需要的朋友可以參考下2023-03-03
基于Django框架的權(quán)限組件rbac實(shí)例講解
今天小編就為大家分享一篇基于Django框架的權(quán)限組件rbac實(shí)例講解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08
Python實(shí)現(xiàn)實(shí)時(shí)增量數(shù)據(jù)加載工具的解決方案
這篇文章主要分享結(jié)合單例模式實(shí)際應(yīng)用案例:實(shí)現(xiàn)實(shí)時(shí)增量數(shù)據(jù)加載工具的解決方案。最關(guān)鍵的是實(shí)現(xiàn)一個(gè)可進(jìn)行添加、修改、刪除等操作的增量ID記錄表。需要的可以參考一下2022-02-02
Anaconda環(huán)境GDAL庫(kù)基于whl文件的配置方法
這篇文章主要介紹了Anaconda環(huán)境GDAL庫(kù)基于whl文件的配置方法,我們介紹了基于conda?install命令直接聯(lián)網(wǎng)安裝GDAL庫(kù)的方法,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
Python3 Post登錄并且保存cookie登錄其他頁(yè)面的方法
今天小編就為大家分享一篇Python3 Post登錄并且保存cookie登錄其他頁(yè)面的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12

