日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

十分钟掌握pyecharts十类顶级图,都很实用!

發布時間:2025/3/8 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 十分钟掌握pyecharts十类顶级图,都很实用! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文是為了幫助大家快速掌握十大頂級繪圖方法,重點解釋數據是如何呈現在不同類型圖中。

使用pip install pyecharts 安裝,安裝后的版本為 v1.6

pyecharts幾行代碼就能繪制出有特色的的圖形,繪圖API鏈式調用,使用方便。

1 儀表盤

from pyecharts import charts# 儀表盤 gauge = charts.Gauge() gauge.add('Python小例子', [('Python機器學習', 30), ('Python基礎', 70.),('Python正則', 90)]) gauge.render(path="./data/儀表盤.html") print('ok')

儀表盤中共展示三項,每項的比例為30%,70%,90%,如下圖默認名稱顯示第一項:Python機器學習,完成比例為30%

2 漏斗圖

from pyecharts import options as opts from pyecharts.charts import Funnel, Page from random import randintdef funnel_base() -> Funnel:c = (Funnel().add("豪車", [list(z) for z in zip(['寶馬', '法拉利', '奔馳', '奧迪', '大眾', '豐田', '特斯拉'],[randint(1, 20) for _ in range(7)])]).set_global_opts(title_opts=opts.TitleOpts(title="豪車漏斗圖")))return cfunnel_base().render('./img/car_funnel.html') print('ok')

以7種車型及某個屬性值繪制的漏斗圖,屬性值大越靠近漏斗的大端。

3 日歷圖

import datetime import randomfrom pyecharts import options as opts from pyecharts.charts import Calendardef calendar_interval_1() -> Calendar:begin = datetime.date(2019, 1, 1)end = datetime.date(2019, 12, 27)data = [[str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]for i in range(0, (end - begin).days + 1, 2) # 隔天統計]calendar = (Calendar(init_opts=opts.InitOpts(width="1200px")).add("", data, calendar_opts=opts.CalendarOpts(range_="2019")).set_global_opts(title_opts=opts.TitleOpts(title="Calendar-2019年步數統計"),visualmap_opts=opts.VisualMapOpts(max_=25000,min_=1000,orient="horizontal",is_piecewise=True,pos_top="230px",pos_left="100px",),))return calendarcalendar_interval_1().render('./img/calendar.html') print('ok')

繪制2019年1月1日到12月27日的步行數,官方給出的圖形寬度900px不夠,只能顯示到9月份,本例使用opts.InitOpts(width="1200px")做出微調,并且visualmap顯示所有步數,每隔一天顯示一次:

4 圖(graph)

import json import osfrom pyecharts import options as opts from pyecharts.charts import Graph, Pagedef graph_base() -> Graph:nodes = [{"name": "cus1", "symbolSize": 10},{"name": "cus2", "symbolSize": 30},{"name": "cus3", "symbolSize": 20}]links = []for i in nodes:if i.get('name') == 'cus1':continuefor j in nodes:if j.get('name') == 'cus1':continuelinks.append({"source": i.get("name"), "target": j.get("name")})c = (Graph().add("", nodes, links, repulsion=8000).set_global_opts(title_opts=opts.TitleOpts(title="customer-influence")))return c

構建圖,其中客戶點1與其他兩個客戶都沒有關系(link),也就是不存在有效邊:

5 水球圖

from pyecharts import options as opts from pyecharts.charts import Liquid, Page from pyecharts.globals import SymbolTypedef liquid() -> Liquid:c = (Liquid().add("lq", [0.67, 0.30, 0.15]).set_global_opts(title_opts=opts.TitleOpts(title="Liquid")))return cliquid().render('./img/liquid.html')

水球圖的取值[0.67, 0.30, 0.15]表示下圖中的三個波浪線,一般代表三個百分比:

6 餅圖

from pyecharts import options as opts from pyecharts.charts import Pie from random import randintdef pie_base() -> Pie:c = (Pie().add("", [list(z) for z in zip(['寶馬', '法拉利', '奔馳', '奧迪', '大眾', '豐田', '特斯拉'],[randint(1, 20) for _ in range(7)])]).set_global_opts(title_opts=opts.TitleOpts(title="Pie-基本示例")).set_series_opts(label_opts=opts.LabelOpts(formatter=": {c}")))return cpie_base().render('./img/pie_pyecharts.html')

7 極坐標

import random from pyecharts import options as opts from pyecharts.charts import Page, Polardef polar_scatter0() -> Polar:data = [(alpha, random.randint(1, 100)) for alpha in range(101)] # r = random.randint(1, 100)print(data)c = (Polar().add("", data, type_="bar", label_opts=opts.LabelOpts(is_show=False)).set_global_opts(title_opts=opts.TitleOpts(title="Polar")))return cpolar_scatter0().render('./img/polar.html')

極坐標表示為(夾角,半徑),如(6,94)表示"夾角"為6,半徑94的點:

8 詞云圖

from pyecharts import options as opts from pyecharts.charts import Page, WordCloud from pyecharts.globals import SymbolTypewords = [("Python", 100),("C++", 80),("Java", 95),("R", 50),("JavaScript", 79),("C", 65) ]def wordcloud() -> WordCloud:c = (WordCloud()# word_size_range: 單詞字體大小范圍.add("", words, word_size_range=[20, 100], shape='cardioid').set_global_opts(title_opts=opts.TitleOpts(title="WordCloud")))return cwordcloud().render('./img/wordcloud.html')

("C",65)表示在本次統計中C語言出現65次

9 系列柱狀圖

from pyecharts import options as opts from pyecharts.charts import Bar from random import randintdef bar_series() -> Bar:c = (Bar().add_xaxis(['寶馬', '法拉利', '奔馳', '奧迪', '大眾', '豐田', '特斯拉']).add_yaxis("銷量", [randint(1, 20) for _ in range(7)]).add_yaxis("產量", [randint(1, 20) for _ in range(7)]).set_global_opts(title_opts=opts.TitleOpts(title="Bar的主標題", subtitle="Bar的副標題")))return cbar_series().render('./img/bar_series.html')


10 熱力圖

import random from pyecharts import options as opts from pyecharts.charts import HeatMapdef heatmap_car() -> HeatMap:x = ['寶馬', '法拉利', '奔馳', '奧迪', '大眾', '豐田', '特斯拉']y = ['中國','日本','南非','澳大利亞','阿根廷','阿爾及利亞','法國','意大利','加拿大']value = [[i, j, random.randint(0, 100)]for i in range(len(x)) for j in range(len(y))]c = (HeatMap().add_xaxis(x).add_yaxis("銷量", y, value).set_global_opts(title_opts=opts.TitleOpts(title="HeatMap"),visualmap_opts=opts.VisualMapOpts(),))return cheatmap_car().render('./img/heatmap_pyecharts.html')

備注:公眾號菜單包含了整理了一本AI小抄非常適合在通勤路上用學習。

往期精彩回顧那些年做的學術公益-你不是一個人在戰斗適合初學者入門人工智能的路線及資料下載機器學習在線手冊深度學習在線手冊AI基礎下載(第一部分)備注:加入本站微信群或者qq群,請回復“加群”加入知識星球(4500+用戶,ID:92416895),請回復“知識星球”

喜歡文章,點個在看

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的十分钟掌握pyecharts十类顶级图,都很实用!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。