python中第三方庫pyecharts的使用詳解
與pyecharts有關(guān)的兩個網(wǎng)站:官方網(wǎng)站:pyecharts - A Python Echarts Plotting Library built with love. ,畫廊功能的網(wǎng)站:
Document
Description
https://gallery.pyecharts.org/#/
在畫廊網(wǎng)站中可以查看各個圖的實例
pyecharts的作用:用來做數(shù)據(jù)圖表
做一個圖的步驟:
1.導(dǎo)包
2.創(chuàng)建一個圖對象
3.添加數(shù)據(jù)
4.設(shè)置全局配置項
5.通過render方法將代碼生成圖像
1.折線圖
# 使用 ab173懶人程序員工具做json數(shù)據(jù)分析 # 1.導(dǎo)包 from pyecharts.charts import Line # TitleOpts:控制圖標(biāo)題的模塊 設(shè)置全局選項時需要引用的模塊 from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts # 2.創(chuàng)建一個折線圖對象 line = Line() # 3.給折線圖對象添加x軸的數(shù)據(jù) line.add_xaxis(['中國', '美國', '英國']) # 4.給折線圖對象添加y軸對象 line.add_yaxis('GDP', [30, 20, 10]) # 5.設(shè)置全局配置項,通過 line.set_global_opts 來設(shè)置 line.set_global_opts( # 標(biāo)題配置 # 參數(shù)列表:title:標(biāo)題,pos_left:x軸橫向位置,pos_bottom:y軸豎向位置 title_opts=TitleOpts(title="GDP展示", pos_left="center", pos_bottom="1%"), # 圖例控制:默認(rèn)是開啟的 legend_opts=LegendOpts(is_show=True), # 工具箱 toolbox_opts=ToolboxOpts(is_show=True), # 視覺映射 visualmap_opts=VisualMapOpts(is_show=True) ) # 6.通過render方法,將代碼生成圖像 line.render('折線圖.html')
【效果】
2. 地圖
# 1.導(dǎo)包 from pyecharts.charts import Map from pyecharts.options import VisualMapOpts # 2.準(zhǔn)備地圖對象 map = Map() # 3.準(zhǔn)備數(shù)據(jù),所用數(shù)據(jù)都是列表嵌套元組 data = [ ("北京", 99), ("上海", 199), ("湖南", 299), ("廣東", 399), ("臺灣", 499), ] # 4.添加數(shù)據(jù) map.add("測試地圖", data, "china") # 5.設(shè)置全局選項 map.set_global_opts( # 視圖功能 visualmap_opts=VisualMapOpts( # 該參數(shù)設(shè)置視圖開啟 is_show=True, # 該參數(shù)改變視圖模式 is_piecewise=True, # 顏色和表簽的設(shè)置 pieces=[ {"min": 1, "max": 9, "label": "1-9", "color": "#CCFFFF"}, {"min": 10, "max": 299, "label": "10-299", "color": "#CC6666"}, {"min": 300, "max": 500, "label": "300-500", "color": "#990033"} ] ) ) # 6.繪圖 map.render("中國部分地圖.html")
【效果】
3. 柱狀圖
# 1.導(dǎo)包 from pyecharts.charts import Bar from pyecharts.options import LabelOpts # 2.創(chuàng)建對象 bar = Bar() # 3.添加數(shù)據(jù) bar.add_xaxis(['中國', '美國', '英國']) bar.add_yaxis("GDP", [30, 20, 10], label_opts=LabelOpts(position="right")) # position可以設(shè)置參數(shù)位置 # 反轉(zhuǎn)x和y軸 bar.reversal_axis() # 4.繪圖 bar.render('基礎(chǔ)柱狀圖.html')
【效果】
4. 基礎(chǔ)時間線柱狀圖
# 1.導(dǎo)包 from pyecharts.charts import Bar, Timeline # 導(dǎo)入時間模塊 from pyecharts.options import LabelOpts from pyecharts.globals import ThemeType # 導(dǎo)入時間線主題 # 2.創(chuàng)建對象 bar1 = Bar() # 3.添加數(shù)據(jù) bar1.add_xaxis(['中國', '美國', '英國']) bar1.add_yaxis("GDP", [30, 20, 10], label_opts=LabelOpts(position="right")) # position可以設(shè)置參數(shù)位置 bar1.reversal_axis() bar2 = Bar() bar2.add_xaxis(['中國', '美國', '英國']) bar2.add_yaxis("GDP", [50, 30, 20], label_opts=LabelOpts(position="right")) # position可以設(shè)置參數(shù)位置 bar2.reversal_axis() bar3 = Bar() bar3.add_xaxis(['中國', '美國', '英國']) bar3.add_yaxis("GDP", [70, 50, 30], label_opts=LabelOpts(position="right")) # position可以設(shè)置參數(shù)位置 bar3.reversal_axis() # 創(chuàng)建時間線對象,傳入一個字典設(shè)置主題 timeline = Timeline({"theme": ThemeType.LIGHT}) # 在時間線添加柱狀圖對象 timeline.add(bar1, "點(diǎn)1") timeline.add(bar2, "點(diǎn)2") timeline.add(bar3, "點(diǎn)3") # 設(shè)置自動播放 timeline.add_schema( play_interval=1000, # 設(shè)置自動播放的時間間隔,單位毫秒 is_timeline_show=True, # 是否在自動播放的時候,顯示時間線 is_auto_play=True, # 是否自動播放 is_loop_play=True # 是否循環(huán)自動播放 ) # 4.繪圖是使用時間線繪圖,而不是bar對象 timeline.render("基礎(chǔ)時間線柱狀圖.html")
【效果】
到此這篇關(guān)于python中第三方庫pyecharts的使用的文章就介紹到這了,更多相關(guān)pythonpyecharts使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python socket套接字實現(xiàn)C/S模式遠(yuǎn)程命令執(zhí)行功能案例
這篇文章主要介紹了Python socket套接字實現(xiàn)C/S模式遠(yuǎn)程命令執(zhí)行功能,涉及Python socket套接字編寫服務(wù)器/客戶機(jī)模式數(shù)據(jù)傳輸相關(guān)操作技巧,需要的朋友可以參考下2018-07-07Python使用read_csv讀數(shù)據(jù)遇到分隔符問題的2種解決方式
read.csv()可以從帶分隔符的文本文件中導(dǎo)入數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于Python使用read_csv讀數(shù)據(jù)遇到分隔符問題的2種解決方式,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07Python光學(xué)仿真實現(xiàn)波長與顏色之間對應(yīng)關(guān)系示例解析
這篇文章主要為大家介紹了Python光學(xué)仿真實現(xiàn)波長與顏色之間對應(yīng)關(guān)系的示例解析,有需要的我朋友可以借鑒參考下,希望能夠有所幫助2021-10-10Pandas groupby apply agg 的區(qū)別 運(yùn)行自定義函數(shù)說明
這篇文章主要介紹了Pandas groupby apply agg 的區(qū)別 運(yùn)行自定義函數(shù)說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03Django JWT Token RestfulAPI用戶認(rèn)證詳解
這篇文章主要介紹了Django JWT Token RestfulAPI用戶認(rèn)證詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01