溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

pyecharts如何實(shí)現(xiàn)數(shù)據(jù)可視化

發(fā)布時間:2022-03-07 09:06:11 來源:億速云 閱讀:240 作者:小新 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)pyecharts如何實(shí)現(xiàn)數(shù)據(jù)可視化,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

1.概述

pyecharts 是百度開源的,適用于數(shù)據(jù)可視化的工具,配置靈活,展示圖表相對美觀,順滑。

pyecharts如何實(shí)現(xiàn)數(shù)據(jù)可視化

2.安裝

python3環(huán)境下的安裝:

pip3 install pyecharts

3.數(shù)據(jù)可視化代碼

3.1 柱狀圖

from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker
 
c = (
    Bar()
    .add_xaxis(Faker.choose())
    .add_yaxis("商家A", Faker.values(), stack="stack1")
    .add_yaxis("商家B", Faker.values(), stack="stack1")
    .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(title_opts=opts.TitleOpts(title="Bar-堆疊數(shù)據(jù)(全部)"))
    .render("bar_stack0.html")
)

執(zhí)行上述代碼,會在相對目錄生成mycharts.html文件,通過頁面打開。

pyecharts如何實(shí)現(xiàn)數(shù)據(jù)可視化

3.2 折線圖

import pyecharts.options as opts
from pyecharts.charts import Line
 
"""
Gallery 使用 pyecharts 1.1.0
參考地址: https://echarts.apache.org/examples/editor.html?c=line-smooth
目前無法實(shí)現(xiàn)的功能:
暫無
"""
 
 
x_data = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
y_data = [820, 932, 901, 934, 1290, 1330, 1320]
 
 
(
    Line()
    .set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(type_="category"),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
    )
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="",
        y_axis=y_data,
        symbol="emptyCircle",
        is_symbol_show=True,
        is_smooth=True,
        label_opts=opts.LabelOpts(is_show=False),
    )
    .render("smoothed_line_chart.html")
)

pyecharts如何實(shí)現(xiàn)數(shù)據(jù)可視化

3.3 餅圖

from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker
 
c = (
    Pie()
    .add(
        "",
        [list(z) for z in zip(Faker.choose(), Faker.values())],
        radius=["40%", "75%"],
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Pie-Radius"),
        legend_opts=opts.LegendOpts(orient="vertical", pos_top="15%", pos_left="2%"),
    )
    .set_series_opts(label_opts=opts.LabelOpts(formatter=": {c}"))
    .render("pie_radius.html")
)

pyecharts如何實(shí)現(xiàn)數(shù)據(jù)可視化

關(guān)于“pyecharts如何實(shí)現(xiàn)數(shù)據(jù)可視化”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI