一、鸢尾花数据集获取
鸢尾花数据集的四个属性sepal_length、sepal_width、petal_length、petal_width分别为萼片长度、萼片宽度、花瓣长度和花瓣宽度。
import pandas as pd
import pyecharts
from pyecharts.charts import Parallel
import pyecharts.options as opts
import numpy as np
url = 'https://www.gairuo.com/file/data/dataset/iris.data'
df = pd.read_csv(url)
二、绘制平行坐标图
dataset = df
data_ = np.array(dataset[["sepal_length", "sepal_width", "petal_length", "petal_width"]]).tolist()
parallel_axis = [{"dim": 0, "name": "萼片长度"},
{"dim": 1, "name": "萼片宽度"},
{"dim": 2, "name": "花瓣长度"},
{"dim": 3, "name": "花瓣宽度"}]
parallel = Parallel(init_opts=opts.InitOpts(width="600px", height="400px"))
parallel.add_schema(schema=parallel_axis)
parallel.add("鸢尾花平行坐标图", data=data_, linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5))
parallel.render('iris.html')