最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python中第三方庫pyecharts的使用詳解

 更新時間:2022年08月25日 14:36:33   作者:愛笑的蛐蛐  
這篇文章主要介紹了python中第三方庫pyecharts的使用, pyecharts的作用是用來做數(shù)據(jù)圖表,本文給大家介紹了作圖的步驟及實例代碼,需要的朋友可以參考下

與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, "點1")
timeline.add(bar2, "點2")
timeline.add(bar3, "點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)文章

最新評論

容城县| 洛隆县| 海安县| 砀山县| 抚顺县| 无极县| 永靖县| 宝鸡市| 醴陵市| 鹿邑县| 高尔夫| 济阳县| 原平市| 溧阳市| 资源县| 石景山区| 德令哈市| 临泉县| 东源县| 卓资县| 梁河县| 衡东县| 枣庄市| 宜春市| 鹰潭市| 雷州市| 富宁县| 泸西县| 安阳县| 凤翔县| 建阳市| 安义县| 霞浦县| 于田县| 衡南县| 荣成市| 都江堰市| 黄冈市| 柘荣县| 临夏县| 安溪县|