pyecharts 十种图形演示

首先要安装模块

conda install pyecharts

或者

pip install pyecharts

具体的echarts操作和介绍可见官网echarts,我也推荐W3Cschool,而pyecharts可以参考pyecharts官网,很详尽。
再进行下面可视化的时候,首先都会引入options

from pyecharts import options as opts

一、仪表盘

代码:

from pyecharts.charts import Gauge

def gauge_base() -> Gauge:
    c = (
        Gauge(init_opts=opts.InitOpts(page_title="仪表盘-演示"))
        .add(
            "", 
            [("我的进化程度", 80)],
            title_label_opts=opts.LabelOpts(horizontal_align="center")
            )
        .set_global_opts(title_opts=opts.TitleOpts(title="仪表盘演示", pos_left="center"))
        )
    return c
gauge_base().render()

效果:
pyecharts 十种图形演示_第1张图片

二、漏斗图

代码:

from pyecharts.charts import Funnel

def funner_base() -> Funnel:
    c = (
        Funnel(init_opts=opts.InitOpts(page_title="漏斗图-演示"))
        .add(
            "funnel",
            [z for z in zip(["第一阶段", "第二阶段", "第三阶段"], [10, 50, 80])],
            label_opts=opts.LabelOpts(position="inside")
            )
        .set_global_opts(title_opts=opts.TitleOpts(title="漏斗图演示", pos_left="right"))
        )
    return c
funner_base().render()

效果:
pyecharts 十种图形演示_第2张图片

三、图

代码:

from pyecharts.charts import Graph

def graph_base() -> Graph:
    nodes = [
        opts.GraphNode(name="节点0", symbol_size=80),
        opts.GraphNode(name="节点1", symbol_size=60),
        opts.GraphNode(name="节点2", symbol_size=60),
        opts.GraphNode(name="节点3", symbol_size=60),
        opts.GraphNode(name="节点4", symbol_size=60),
        opts.GraphNode(name="节点1.1", symbol_size=40),
        opts.GraphNode(name="节点1.2", symbol_size=40),
        opts.GraphNode(name="节点1.3", symbol_size=40),
        opts.GraphNode(name="节点1.4", symbol_size=40),
        opts.GraphNode(name="节点3.1", symbol_size=40),
        opts.GraphNode(name="节点3.2", symbol_size=40),
        opts.GraphNode(name="节点3.3", symbol_size=40),
        opts.GraphNode(name="节点3.4", symbol_size=40),
        opts.GraphNode(name="节点3.3.1", symbol_size=20),
        opts.GraphNode(name="节点3.3.2", symbol_size=20),
        opts.GraphNode(name="节点3.3.3", symbol_size=20),
        opts.GraphNode(name="节点3.3.4", symbol_size=20)
        ]
    links = [
        opts.GraphLink(source="节点0", target="节点1", value=1),
        opts.GraphLink(source="节点0", target="节点2", value=1),
        opts.GraphLink(source="节点0", target="节点3", value=1),
        opts.GraphLink(source="节点0", target="节点4", value=1),
        opts.GraphLink(source="节点1", target="节点1.1", value=2),
        opts.GraphLink(source="节点1", target="节点1.2", value=2),
        opts.GraphLink(source="节点1", target="节点1.3", value=2),
        opts.GraphLink(source="节点1", target="节点1.4", value=2),
        opts.GraphLink(source="节点3", target="节点3.1", value=2),
        opts.GraphLink(source="节点3", target="节点3.2", value=2),
        opts.GraphLink(source="节点3", target="节点3.3", value=2),
        opts.GraphLink(source="节点3", target="节点3.4", value=2),
        opts.GraphLink(source="节点3.3", target="节点3.3.1", value=3),
        opts.GraphLink(source="节点3.3", target="节点3.3.2", value=3),
        opts.GraphLink(source="节点3.3", target="节点3.3.3", value=3),
        opts.GraphLink(source="节点3.3", target="节点3.3.4", value=3),
        ]
    c = (
        Graph(init_opts=opts.InitOpts(width="1080px", height="700px", page_title="图-演示"))
        .add(
            "graph",
            nodes,
            links,
            label_opts=opts.LabelOpts(position="inside"),
            repulsion=2000,
            is_draggable=True,
            layout="force",
            symbol="roundRect",
            edge_label=opts.LabelOpts(
                is_show=True,
                position="middle",
                formatter="{b} "
                )
            )
        .set_global_opts(title_opts=opts.TitleOpts(title="图演示", pos_left="center"))
        )
    return c
graph_base().render()

效果:
pyecharts 十种图形演示_第3张图片

四、水球图

代码:

from pyecharts.charts import Liquid

def liquid_base() -> Liquid:
    c = (
        Liquid(init_opts=opts.InitOpts(page_title="水球图-演示"))
        .add(
            "liquid",
            [0.78],
            shape="rect"
            )
        .set_global_opts(title_opts=opts.TitleOpts(title="水球图", pos_left="center"))
        )
    return c
liquid_base().render()

效果:
pyecharts 十种图形演示_第4张图片

五、饼图

代码:

from pyecharts.charts import Pie

def pie_base() -> Pie:
    c = (
        Pie(init_opts=opts.InitOpts(page_title="饼图-演示"))
        .add(
            "pie",
            [("男人购物花费", 20), ("女人购物花费", 80)],
            radius=["40%", "60%"],
            center=["50%", "50%"],
            label_opts=opts.LabelOpts(formatter="{b}:{c}%")
            )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="饼图", pos_left="center", pos_top="10%"),
            legend_opts=opts.LegendOpts(orient="vertical", pos_right="20%", pos_top="50%")
            )
        )
    return c
pie_base().render()

效果:
pyecharts 十种图形演示_第5张图片

六、词云图

代码:

from pyecharts.charts import WordCloud

def wcloud_base() -> WordCloud:
    words = [("我",10000), ("比尔盖茨",9000), ("索罗斯",8000), ("马云",7000), ("马化腾",6000), ("史玉柱",4000), ("王传福",900), ("*大大",10000), ("徐凤年",10000), ("洪敬岩",3000), ("王初冬",2000), ("剑来",1000)]
    c = (
        WordCloud(init_opts=opts.InitOpts(page_title="词云图-演示"))
        .add(
            "wordcloud",
            words,
            shape="cardioid"
            )
        .set_global_opts(title_opts=opts.TitleOpts(title="词云图", pos_left="center"))
        )
    return c
wcloud_base().render()

效果:
pyecharts 十种图形演示_第6张图片

七、柱状图

代码:

from pyecharts.charts import Bar
from pyecharts.commons.utils import JsCode

def bar_base() -> Bar:
    c = (
        Bar(init_opts=opts.InitOpts(page_title="柱状图-演示"))
        .add_xaxis(
            ["现有确诊/累计确诊", "现有疑似/累计治愈", "现有重症/累计死亡"]
            )
        .add_yaxis(
            "",
            [29994, 587, 6806]
            )
        .add_yaxis(
            "",
            [80303, 47362, 2947]
            )
        .set_series_opts(
            itemstyle_opts={
                "color":JsCode("""{
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [
                        {offset: 0, color: 'red'}, 
                        {offset: 1, color: 'blue'}
                        ],
                    global: false
                    }"""
                    )
                }
            )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="2020年03月03日疫情实时大数据", pos_left="center"),
            legend_opts=opts.LegendOpts(orient="victical", pos_right="10%", pos_top="center")
            )
        )
    return c
bar_base().render()

效果:
pyecharts 十种图形演示_第7张图片

八、雷达图

代码:

from pyecharts.charts import Radar

def radar_base() -> Radar:
    c = (
        Radar(init_opts=opts.InitOpts(page_title="雷达图-演示"))
        .add_schema(
            schema=[
                opts.RadarIndicatorItem(name="编程水平", max_=100),
                opts.RadarIndicatorItem(name="数学基本功", max_=100),
                opts.RadarIndicatorItem(name="记忆力", max_=100),
                opts.RadarIndicatorItem(name="理解力", max_=100),
                opts.RadarIndicatorItem(name="自学能力", max_=100),
                opts.RadarIndicatorItem(name="抗压能力", max_=100)
                ],
            shape="circle"
            )
        .add(
            "我的表现",
            [[60, 65, 30, 55, 75, 70]],
            areastyle_opts=opts.AreaStyleOpts(opacity=0.1)
            )
        .add(
            "平均水平",
            [[60, 60, 60, 60, 60, 60]],
            linestyle_opts=opts.LineStyleOpts(width=2, color='blue')
            )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="雷达图", pos_left="center"),
            legend_opts=opts.LegendOpts(pos_right="20%", pos_top="10%", orient="vectical")
            )
        )
    return c
radar_base().render()

效果:
pyecharts 十种图形演示_第8张图片

九、旭日图

其实就是日头爆炸图
代码:

from pyecharts.charts import Sunburst

def sunburst_base() -> Sunburst:
    data = [
        opts.SunburstItem(
            name="数据采集",
            children=[
                opts.SunburstItem(name="爬虫", value=50),
                opts.SunburstItem(name="交换共享", value=20),
                opts.SunburstItem(name="第三方购买", value=20),
                opts.SunburstItem(name="其他方式", value=10)
                ]
            ),
        opts.SunburstItem(
            name="数据存储",
            children=[
                opts.SunburstItem(name="关系型数据库", value=60),
                opts.SunburstItem(name="键值存储库", value=10),
                opts.SunburstItem(name="列式存储库", value=10),
                opts.SunburstItem(name="面向文档数据库", value=10),
                opts.SunburstItem(name="图数据库", value=10)
                ]
            ),
        opts.SunburstItem(
            name="数据处理",
            children=[
                opts.SunburstItem(name="空值填充", value=20),
                opts.SunburstItem(name="异常值处理", value=20),
                opts.SunburstItem(name="新增特征", value=20),
                opts.SunburstItem(name="热编码", value=20),
                opts.SunburstItem(name="标准化处理", value=20)
                ]
            ),
        opts.SunburstItem(
            name="数据统计分析",
            children=[
                opts.SunburstItem(name="描述性分析", value=30),
                opts.SunburstItem(name="多维度统计", value=40),
                opts.SunburstItem(name="对比统计", value=30)
                ]
            ),
        opts.SunburstItem(
            name="数据挖掘",
            children=[
                opts.SunburstItem(name="分类", value=30),
                opts.SunburstItem(name="预测", value=30),
                opts.SunburstItem(name="聚类", value=20),
                opts.SunburstItem(name="回归", value=20)
                ]
            ),
        opts.SunburstItem(
            name="数据展示",
            children=[
                opts.SunburstItem(name="大屏展示", value=20),
                opts.SunburstItem(name="系统页面展示", value=40),
                opts.SunburstItem(name="报告展示", value=40),
                ]
            ),
        opts.SunburstItem(
            name="数据产品应用",
            children=[
                opts.SunburstItem(name="推荐系统", value=30),
                opts.SunburstItem(name="翻译系统", value=20),
                opts.SunburstItem(name="自动驾驶", value=15),
                opts.SunburstItem(name="人脸识别", value=15),
                opts.SunburstItem(name="图片识别文字", value=20)
                ]
            )
        ]
    c = (
        Sunburst(init_opts=opts.InitOpts(page_title="旭日图-演示"))
        .add(
            "sunburst",
            data,
            radius=["20%", "85%"]
            )
        .set_global_opts(title_opts=opts.TitleOpts(title="旭日图", pos_left="center"))
        )
    return c
sunburst_base().render()

效果:

pyecharts 十种图形演示_第9张图片

更多情况可以参考ecahrts官网或pyecharts官网,还推荐一个echarts社区,里面有很多富有创意的可视化

你可能感兴趣的:(Python,数据分析)