欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

平行坐标系

程序员文章站 2022-05-26 22:02:21
...

Parallel(平行坐标系)

平行坐标系是一种常用的可视化高维数据的图表。

from pyecharts import Parallel

schema = ["data", "AQI", "PM2.5", "PM10", "CO", "NO2"]
data = [
        [1, 91, 45, 125, 0.82, 34],
        [2, 65, 27, 78, 0.86, 45,],
        [3, 83, 60, 84, 1.09, 73],
        [4, 109, 81, 121, 1.28, 68],
        [5, 106, 77, 114, 1.07, 55],
        [6, 109, 81, 121, 1.28, 68],
        [7, 106, 77, 114, 1.07, 55],
        [8, 89, 65, 78, 0.86, 51, 26],
        [9, 53, 33, 47, 0.64, 50, 17],
        [10, 80, 55, 80, 1.01, 75, 24],
        [11, 117, 81, 124, 1.03, 45]
]
parallel = Parallel("平行坐标系-默认指示器")
parallel.config(schema) 
parallel.add("parallel", data, is_random=True)
parallel
<div id="2f009dc11f9b438faf14c891642ae5e8" style="width:800px;height:400px;"></div>
from pyecharts import Parallel

c_schema = [
    {"dim": 0, "name": "data"},
    {"dim": 1, "name": "AQI"},
    {"dim": 2, "name": "PM2.5"},
    {"dim": 3, "name": "PM10"},
    {"dim": 4, "name": "CO"},
    {"dim": 5, "name": "NO2"},
    {"dim": 6, "name": "CO2"},
    {"dim": 7, "name": "等级",
     "type": "category",
     "data": ['优', '良', '轻度污染', '中度污染', '重度污染', '严重污染']}
]
data = [
    [1, 91, 45, 125, 0.82, 34, 23, "良"],
    [2, 65, 27, 78, 0.86, 45, 29, "良"],
    [3, 83, 60, 84, 1.09, 73, 27, "良"],
    [4, 109, 81, 121, 1.28, 68, 51, "轻度污染"],
    [5, 106, 77, 114, 1.07, 55, 51, "轻度污染"],
    [6, 109, 81, 121, 1.28, 68, 51, "轻度污染"],
    [7, 106, 77, 114, 1.07, 55, 51, "轻度污染"],
    [8, 89, 65, 78, 0.86, 51, 26, "良"],
    [9, 53, 33, 47, 0.64, 50, 17, "良"],
    [10, 80, 55, 80, 1.01, 75, 24, "良"],
    [11, 117, 81, 124, 1.03, 45, 24, "轻度污染"],
    [12, 99, 71, 142, 1.1, 62, 42, "良"],
    [13, 95, 69, 130, 1.28, 74, 50, "良"],
    [14, 116, 87, 131, 1.47, 84, 40, "轻度污染"]
]
parallel = Parallel("平行坐标系-用户自定义指示器")
parallel.config(c_schema=c_schema)
parallel.add("parallel", data)
parallel
<div id="d1caac03b2434d79bf9354b1844d3393" style="width:800px;height:400px;"></div>
from pyecharts import Parallel

c_schema = [
    {"dim": 0, "name": "City",
     "type": "category",
     "data": ['北京', '上海', '沈阳', '深圳', '南京', '成都','兰州']},
    {"dim": 1, "name": "AQI"},
    {"dim": 2, "name": "PM2.5"},
    {"dim": 3, "name": "PM10"},
    {"dim": 4, "name": "CO"},
    {"dim": 5, "name": "NO2"},
    {"dim": 6, "name": "CO2"},
    {"dim": 7, "name": "等级",
     "type": "category",
     "data": ['优', '良', '轻度污染', '中度污染', '重度污染', '严重污染']}
]
data = [
    ['北京', 91, 45, 125, 0.82, 34, 23, "严重污染"],
    ['上海', 65, 27, 78, 0.86, 45, 29, "重度污染"],
    ['沈阳', 83, 60, 84, 1.09, 73, 27, "良"],
    ['深圳', 109, 81, 121, 1.28, 68, 51, "轻度污染"],
    ['南京', 106, 77, 114, 1.07, 55, 51, "中度污染"],
    ['成都', 109, 81, 121, 1.28, 68, 51, "优"],
    ['兰州', 106, 77, 114, 1.07, 55, 51, "轻度污染"]
]
parallel = Parallel("平行坐标系-用户自定义指示器")
parallel.config(c_schema=c_schema)
parallel.add("parallel", data)
parallel
<div id="98d2392d868842818d6d969c91096d69" style="width:800px;height:400px;"></div>
from pyecharts import Parallel
import pandas as pd
import numpy as np
import random

quarters = ['产品大类','2016Q1','2016Q2','2016Q3','2016Q4','2017Q1','2017Q2','2017Q3','2017Q4','2018Q1']

c_schema = []
d = ['其他', '装饰用品', '厨具', '地毯', '床上纺织品', '照明',
     '餐厅', '厨房', '浴室', '床垫', '卧室', '工作区', '存储']
data = []
data.append(d)

for i,q in enumerate(quarters):
    c_schema_tmp = {}
    if i == 0:
        c_schema_tmp['dim'], c_schema_tmp['name'], c_schema_tmp['type'],c_schema_tmp['data'] = i,q,'category',d
    else:
        rank = list(range(1,14))
        rank.reverse()
        c_schema_tmp['dim'], c_schema_tmp['name'], c_schema_tmp['type'],c_schema_tmp['data'] = i,q,'category',rank
        v = list(range(1,14))
        random.shuffle(v)
        data.append(v)
    c_schema.append(c_schema_tmp)
data = np.array(data).T
parallel = Parallel("某家具厂商大类产品销量排行变化情况", '模拟数据', width=1200, height=700)
parallel.config(c_schema=c_schema)

for i,j in enumerate(d):
    parallel.add(j, [data[i]], is_random=True,
                 line_width=4,
                 is_legend_show=True, legend_top='50',
                 legend_selectedmode='single',
                )
parallel
<div id="68003a650bc341a8b66859a96c8adb2d" style="width:1200px;height:700px;"></div>
print(c_schema)
[{'type': 'category', 'data': ['其他', '装饰用品', '厨具', '地毯', '床上纺织品', '照明', '餐厅', '厨房', '浴室', '床垫', '卧室', '工作区', '存储'], 'dim': 0, 'name': '产品大类'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 1, 'name': '2016Q1'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 2, 'name': '2016Q2'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 3, 'name': '2016Q3'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 4, 'name': '2016Q4'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 5, 'name': '2017Q1'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 6, 'name': '2017Q2'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 7, 'name': '2017Q3'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 8, 'name': '2017Q4'}, {'type': 'category', 'data': [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 'dim': 9, 'name': '2018Q1'}]
data
array([['其他', '2', '10', '5', '5', '9', '2', '11', '4', '5'],
       ['装饰用品', '5', '9', '12', '13', '10', '3', '5', '3', '8'],
       ['厨具', '3', '13', '6', '11', '5', '9', '9', '6', '6'],
       ['地毯', '12', '4', '3', '10', '12', '11', '6', '2', '9'],
       ['床上纺织品', '6', '2', '13', '3', '3', '10', '8', '10', '10'],
       ['照明', '4', '11', '8', '7', '8', '6', '2', '7', '3'],
       ['餐厅', '10', '1', '10', '1', '6', '5', '13', '1', '7'],
       ['厨房', '7', '3', '9', '8', '13', '8', '10', '13', '13'],
       ['浴室', '9', '8', '2', '2', '7', '12', '12', '8', '4'],
       ['床垫', '11', '7', '11', '6', '11', '4', '4', '12', '2'],
       ['卧室', '1', '5', '7', '12', '1', '13', '7', '11', '11'],
       ['工作区', '8', '12', '1', '9', '4', '1', '1', '5', '1'],
       ['存储', '13', '6', '4', '4', '2', '7', '3', '9', '12']], dtype='<U5')

相关标签: 数据科学