Skip to main content
 首页 » 编程设计

python之在 Pandas / python 中绘制平行坐标

2025年04月02日15langtianya

我正在尝试在 python 中使用 pandas 来绘制以下高维数据: http://i.stack.imgur.com/34nbR.jpg

这是我的代码:

import pandas 
from pandas.tools.plotting import parallel_coordinates 
 
data = pandas.read_csv('ParaCoords.csv') 
parallel_coordinates(data,'Name') 

代码绘制数据失败,Traceback 错误结束于:

Keyerror: 'Name' 

parallel_coordinates 中的第二个参数应该说/做什么? 如何成功绘制数据?

请您参考如下方法:

第二个参数应该是定义 class 的列名。想想 ['dog', 'dog', 'cat', 'bird', 'cat', 'dog']。

在example online他们使用 'Name' 作为第二个参数,因为这是一个定义 iris 名称的列

文档

Signature: parallel_coordinates(*args, **kwargs) 
Docstring: 
Parallel coordinates plotting. 
 
Parameters 
---------- 
frame: DataFrame 
class_column: str 
    Column name containing class names 
cols: list, optional 
    A list of column names to use 
ax: matplotlib.axis, optional 
    matplotlib axis object 
color: list or tuple, optional 
    Colors to use for the different classes 
use_columns: bool, optional 
    If true, columns will be used as xticks 
xticks: list or tuple, optional 
    A list of values to use for xticks 
colormap: str or matplotlib colormap, default None 
    Colormap to use for line colors. 
axvlines: bool, optional 
    If true, vertical lines will be added at each xtick 
axvlines_kwds: keywords, optional 
    Options to be passed to axvline method for vertical lines 
kwds: keywords 
    Options to pass to matplotlib plotting method