pyecharts各种图表实现(超级全)(下)

简介: 以下默认都是在Jupyter Notebook展示 也可以将每个图代码的最后一行换为 所创建的对象.render('名字.html')转换为html文件就可以查看啦

关系图

nodes = [
    {"name": "结点1", "symbolSize": 1},
    {"name": "结点2", "symbolSize": 2},
    {"name": "结点3", "symbolSize": 3},
    {"name": "结点4", "symbolSize": 4},
    {"name": "结点5", "symbolSize": 5},
    {"name": "结点6", "symbolSize": 6},
    {"name": "结点7", "symbolSize": 7},
    {"name": "结点8", "symbolSize": 8},
]
links = [{'source': '结点1', 'target': '结点2'},
         {'source': '结点1', 'target': '结点3'},
         {'source': '结点1', 'target': '结点4'},
         {'source': '结点2', 'target': '结点1'},
         {'source': '结点3', 'target': '结点4'},
         {'source': '结点3', 'target': '结点5'},
         {'source': '结点3', 'target': '结点6'},
         {'source': '结点4', 'target': '结点1'},
         {'source': '结点4', 'target': '结点2'},
         {'source': '结点4', 'target': '结点7'},
         {'source': '结点4', 'target': '结点8'},
         {'source': '结点5', 'target': '结点1'},
         {'source': '结点5', 'target': '结点4'},
         {'source': '结点5', 'target': '结点6'},
         {'source': '结点5', 'target': '结点7'},
         {'source': '结点5', 'target': '结点8'},
         {'source': '结点6', 'target': '结点1'},
         {'source': '结点6', 'target': '结点7'},
         {'source': '结点6', 'target': '结点8'},
         {'source': '结点7', 'target': '结点1'},
         {'source': '结点7', 'target': '结点2'},
         {'source': '结点7', 'target': '结点8'},
         {'source': '结点8', 'target': '结点1'},
         {'source': '结点8', 'target': '结点2'},
         {'source': '结点8', 'target': '结点3'},
         ]
graph = (
    Graph()
    .add("", nodes, links)
)
graph.render_notebook()

2345_image_file_copy_47.jpg

平行坐标系

# 虚假数据
data = [
    ['一班', 78, 91, 123, 78, 82, 67, "优秀"],
    ['二班', 89, 101, 127, 88, 86, 75, "良好"],
    ['三班', 86, 93, 101, 84, 90, 73, "合格"],
]
parallel = (
    Parallel()
    .add_schema(
        [
            opts.ParallelAxisOpts(
                dim=0,
                name="班级",
                type_="category",
                data=["一班", "二班", "三班"],
            ),
            opts.ParallelAxisOpts(dim=1, name="英语"),
            opts.ParallelAxisOpts(dim=2, name="数学"),
            opts.ParallelAxisOpts(dim=3, name="语文"),
            opts.ParallelAxisOpts(dim=4, name="物理"),
            opts.ParallelAxisOpts(dim=5, name="生物"),
            opts.ParallelAxisOpts(dim=6, name="化学"),
            opts.ParallelAxisOpts(
                dim=7,
                name="评级",
                type_="category",
                data=["优秀", "良好", "合格"],
            ),
        ]
    )
    .add("", data)
)
parallel.render_notebook()

2345_image_file_copy_48.jpg

极坐标系

# 虚假数据
cate = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu']
data = [123, 153, 89, 107, 98, 23]
polar = (
    Polar()
    .add_schema(
        radiusaxis_opts=opts.RadiusAxisOpts(data=cate, type_="category"),
    )
    .add("", data, type_='bar')
)
polar.render_notebook()

2345_image_file_copy_49.jpg

雷达图

# 虚假数据
data = [
    [78, 91, 123, 78, 82, 67],
    [89, 101, 127, 88, 86, 75],
    [86, 93, 101, 84, 90, 73],
]
radar = (Radar()
         .add_schema(schema=[
             opts.RadarIndicatorItem(name="语文", max_=150),
             opts.RadarIndicatorItem(name="数学", max_=150),
             opts.RadarIndicatorItem(name="英语", max_=150),
             opts.RadarIndicatorItem(name="物理", max_=100),
             opts.RadarIndicatorItem(name="生物", max_=100),
             opts.RadarIndicatorItem(name="化学", max_=100),
         ]
)
    .add('', data)
)
radar.render_notebook()

2345_image_file_copy_50.jpg

旭日图

# 虚假数据
data = [
    {"name": "湖南",
     "children": [
             {"name": "长沙",
              "children": [
                  {"name": "雨花区", "value": 55},
                  {"name": "岳麓区", "value": 34},
                  {"name": "天心区", "value": 144},
              ]},
             {"name": "常德",
              "children": [
                      {"name": "武陵区", "value": 156},
                      {"name": "鼎城区", "value": 134},
              ]},
             {"name": "湘潭", "value": 87},
             {"name": "株洲", "value": 23},
     ],
     },
    {"name": "湖北",
     "children": [
             {"name": "武汉",
              "children": [
                  {"name": "洪山区", "value": 55},
                  {"name": "东湖高新", "value": 78},
                  {"name": "江夏区", "value": 34},
              ]},
             {"name": "鄂州", "value": 67},
             {"name": "襄阳", "value": 34},
     ],
     },
    {"name": "北京", "value": 235}
]
sunburst = (Sunburst()
            .add("", data_pair=data)
            )
sunburst.render_notebook()

2345_image_file_copy_55.jpg

桑基图

# 虚假数据
nodes = [
    {"name": "访问"},
    {"name": "注册"},
    {"name": "付费"},
]
links = [
    {"source": "访问", "target": "注册", "value": 50},
    {"source": "注册", "target": "付费", "value": 30},
]
sankey = (
    Sankey()
    .add("", nodes, links)
)
sankey.render_notebook()

2345_image_file_copy_56.jpg

河流图

# 虚假数据
cate = ['Apple', 'Huawei', 'Xiaomi', 'Oppo', 'Vivo', 'Meizu']
date_list = ["2020/4/{}".format(i + 1) for i in range(30)]
data = [[day, random.randint(10, 50), c] for day in date_list for c in cate]
river = (
    ThemeRiver()
    .add(
        series_name=cate,
        data=data,
        singleaxis_opts=opts.SingleAxisOpts(type_="time")
    )
)
river.render_notebook()

2345_image_file_copy_57.jpg

词云

words = [
    ("hey", 230),
    ("jude", 124),
    ("dont", 436),
    ("make", 255),
    ("it", 247),
    ("bad", 244),
    ("Take", 138),
    ("a sad song", 184),
    ("and", 12),
    ("make", 165),
    ("it", 247),
    ("better", 182),
    ("remember", 255),
    ("to", 150),
    ("let", 162),
    ("her", 266),
    ("into", 60),
    ("your", 82),
    ("heart", 173),
    ("then", 365),
    ("you", 360),
    ("can", 282),
    ("start", 273),
    ("make", 265),
]
wc = (
    WordCloud()
    .add("", words)
)
wc.render_notebook()

2345_image_file_copy_58.jpg

表格

from pyecharts.components import Table
table = Table()
headers = ["City name", "Area", "Population", "Annual Rainfall"]
rows = [
    ["Brisbane", 5905, 1857594, 1146.4],
    ["Adelaide", 1295, 1158259, 600.5],
    ["Darwin", 112, 120900, 1714.7],
    ["Hobart", 1357, 205556, 619.5],
    ["Sydney", 2058, 4336374, 1214.8],
    ["Melbourne", 1566, 3806092, 646.9],
    ["Perth", 5386, 1554769, 869.4],
]
table.add(headers, rows)
table.render_notebook()

City name Area Population Annual Rainfall

Brisbane 5905 1857594 1146.4

Adelaide 1295 1158259 600.5

Darwin 112 120900 1714.7

Hobart 1357 205556 619.5

Sydney 2058 4336374 1214.8

Melbourne 1566 3806092 646.9

Perth 5386 1554769 869.4

3D图表

3D散点图

data = [(random.randint(0, 100), random.randint(0, 100), random.randint(0, 100)) for _ in range(100)]
scatter3D = (Scatter3D()
             .add("", data)
             )
scatter3D.render_notebook()

3D折线图

data = []
for t in range(0, 1000):
    x = math.cos(t/10)
    y = math.sin(t/10)
    z = t/10
    data.append([x, y, z])
line3D = (Line3D()
          .add("", data,
               xaxis3d_opts=opts.Axis3DOpts(type_="value"),
               yaxis3d_opts=opts.Axis3DOpts(type_="value"))
          )
line3D.render_notebook()

3D直方图

data = [[i, j, random.randint(0, 100)] for i in range(24) for j in range(7)]
hour_list = [str(i) for i in range(24)]
week_list = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
bar3D = (
    Bar3D()
    .add(
        "",
        data,
        xaxis3d_opts=opts.Axis3DOpts(hour_list, type_="category"),
        yaxis3d_opts=opts.Axis3DOpts(week_list, type_="category"),
        zaxis3d_opts=opts.Axis3DOpts(type_="value"),
    )
)
bar3D.render_notebook()

3D地图

# 虚假数据
province = [
    '广东',
    '湖北',
    '湖南',
    '四川',
    '重庆',
    '黑龙江',
    '浙江',
    '山西',
    '河北',
    '安徽',
    '河南',
    '山东',
    '西藏']
data = [(i, random.randint(50, 150)) for i in province]
map3d = (
    Map3D()
    .add("", data_pair=data, maptype='china')
)
map3d.render_notebook()
3D地球
from pyecharts.faker import POPULATION
mapglobe = (
    MapGlobe()
    .add_schema()
    .add(
        series_name="",
        maptype="world",
        data_pair=POPULATION[1:]
    )
)
mapglobe.render_notebook()

树型图表

树图

# 虚假数据
data = [
    {"name": "湖南",
     "children": [
             {"name": "长沙",
              "children": [
                  {"name": "雨花区", "value": 55},
                  {"name": "岳麓区", "value": 34},
                  {"name": "天心区", "value": 144},
              ]},
             {"name": "常德",
              "children": [
                      {"name": "武陵区", "value": 156},
                      {"name": "鼎城区", "value": 134},
              ]},
             {"name": "湘潭", "value": 87},
             {"name": "株洲", "value": 23},
     ],
     }
]
tree = (
    Tree()
    .add("", data)
)
tree.render_notebook()

2345_image_file_copy_59.jpg

矩形树图

# 虚假数据
data = [
    {"name": "湖南",
     "children": [
             {"name": "长沙",
              "children": [
                  {"name": "雨花区", "value": 55},
                  {"name": "岳麓区", "value": 34},
                  {"name": "天心区", "value": 144},
              ]},
             {"name": "常德",
              "children": [
                      {"name": "武陵区", "value": 156},
                      {"name": "鼎城区", "value": 134},
              ]},
             {"name": "湘潭", "value": 87},
             {"name": "株洲", "value": 23},
     ],
     },
    {"name": "湖北",
     "children": [
             {"name": "武汉",
              "children": [
                  {"name": "洪山区", "value": 55},
                  {"name": "东湖高新", "value": 78},
                  {"name": "江夏区", "value": 34},
              ]},
             {"name": "鄂州", "value": 67},
             {"name": "襄阳", "value": 34},
     ],
     },
    {"name": "北京", "value": 235}
]
treemap = (
    TreeMap()
    .add("", data)
)
treemap.render_notebook()

2345_image_file_copy_60.jpg

目录
相关文章
|
数据可视化 Python
【100天精通Python】Day62:Python可视化_Matplotlib绘图基础,绘制折线图、散点图、柱状图、直方图和饼图,以及自定义图标外观和功能,示例+代码
【100天精通Python】Day62:Python可视化_Matplotlib绘图基础,绘制折线图、散点图、柱状图、直方图和饼图,以及自定义图标外观和功能,示例+代码
203 0
|
数据可视化 Python
【100天精通Python】Day65:Python可视化_Matplotlib3D绘图mplot3d,绘制3D散点图、3D线图和3D条形图,示例+代码
【100天精通Python】Day65:Python可视化_Matplotlib3D绘图mplot3d,绘制3D散点图、3D线图和3D条形图,示例+代码
356 0
|
6月前
|
数据可视化 Python
使用pyecharts库绘制柱状图:基础与进阶
使用pyecharts库绘制柱状图:基础与进阶
140 0
|
6月前
|
数据采集 机器学习/深度学习 JSON
写【Python折线图】的一百个技巧(一、生成折线图网页)
写【Python折线图】的一百个技巧(一、生成折线图网页)
108 0
|
数据可视化
可视化 | Pyecharts 单轴散点图(附完整代码)
可视化 | Pyecharts 单轴散点图(附完整代码)
|
Python
Python常用画图代码(折线图、柱状图、饼图)
Python常用画图代码(折线图、柱状图、饼图)
232 0
|
Python
python pyecharts 画图 饼图柱状图
python pyecharts 画图 饼图柱状图
228 0
python pyecharts 画图 饼图柱状图
|
开发者
pyecharts基础之柱状图的绘制
pyecharts分为v0.5.X和v1两个大版本,0.5.x 版本将不再进行维护推荐使用v1版本
108 0
|
数据可视化 数据挖掘 数据处理
python柱状图可视化图例
数据分析 可视化 柱状图 条形图 pyecharts
python柱状图可视化图例
|
机器学习/深度学习 数据可视化 Python
Python中得可视化:使用Seaborn绘制常用图表(下)
Python中得可视化:使用Seaborn绘制常用图表
437 0
Python中得可视化:使用Seaborn绘制常用图表(下)
下一篇
无影云桌面