Python 在Pandas.plotting.parallel_坐标中的打印顺序

Python 在Pandas.plotting.parallel_坐标中的打印顺序,python,pandas,matplotlib,parallel-coordinates,Python,Pandas,Matplotlib,Parallel Coordinates,我有一系列的测量值,我想绘制为pandas.plotting.parallel_坐标,其中每条线的颜色由一个pandas.column的值给出 代码如下所示: ... data retrieval and praparation from a couple of Excel files ---> output = 'largeDataFrame' theColormap: ListedColormap = cm.get_cmap('some cmap name') # This is

我有一系列的测量值,我想绘制为pandas.plotting.parallel_坐标,其中每条线的颜色由一个pandas.column的值给出

代码如下所示:

... data retrieval and praparation from a couple of Excel files
---> output = 'largeDataFrame'

theColormap: ListedColormap = cm.get_cmap('some cmap name')

# This is a try to stack the lines in the right order.. (doesn't work)
largeDataFrames.sort_values(column_for_line_color_derivation, inplace=True, ascending=True)

# here comes the actual plotting of data
sns.set_style('ticks')
sns.set_context('paper')
plt.figure(figsize=(10, 6))
thePlot: plt.Axes = parallel_coordinates(largeDataFrame, class_column=column_for_line_color_derivation, cols=[columns to plot], color=theColormap.colors)
plt.title('My Title')
thePlot.get_legend().remove()
plt.xticks(rotation=90)
plt.tight_layout()
plt.show()
这项工作非常有效,并产生以下结果:


现在我想把黄线(高值的“column_for_line_color_derivation”)绘制在绿色和深色线的前面,这样它们会变得更加突出。换句话说,我想通过“column\u for\u line\u color\u derivation”的值来影响行的堆叠顺序。到目前为止,我还没有找到这样做的方法。

我对pandas版本1.1.2和1.0.3进行了一些测试,在这两种情况下,线都是从着色列的低值到高值绘制的,与数据帧顺序无关

您可以临时添加
平行坐标(..,lw=5)
,这非常清楚。对于细线,顺序不太明显,因为黄线的对比度较小

参数
sort\u labels=
似乎与其名称具有相反的效果:当
False
(默认值)时,线按排序顺序绘制,当
True
时,它们保持数据帧顺序

以下是一个可重复的小示例:

将numpy导入为np
作为pd进口熊猫
从pandas.plotting导入平行坐标
将matplotlib.pyplot作为plt导入
df=pd.DataFrame({ch:np.random.randn(100)表示ch in'abcde'})
df['coloring']=np.random.randn(len(df))
图,轴=plt.子批次(ncols=2,figsize=(14,6))
对于轴,拉链中的lw(轴[1,5]):
平行坐标(df,class_column='coloring',cols=df.columns[:-1],colormap='viridis',ax=ax,lw=lw)
ax.set_title(f'linewidth={lw}')
ax.get_legend().remove()
plt.show()

一个想法是根据类别更改线宽:

fig,ax=plt.子批次(figsize=(8,6))
平行坐标(df,class_column='coloring',cols=df.columns[:-1],colormap='viridis',ax=ax)
数量线=长度(最大线)
对于ind,枚举中的行(最大行):
xs=line.get_xdata()
如果xs[0]!=xs[-1]:#跳过代表轴的垂直线
行。设置行宽(1+3*ind/num行)
ax.设置标题(f'线宽取决于类别列')
ax.get_legend().remove()
plt.show()

我猜它们可能是按照它们在数据帧中出现的顺序绘制的。您是否尝试过按所讨论的列对数据帧进行排序?嗨,Paul,是的,我这样做了-尝试通过行“allFrames.sort\u values(column\u表示\u line\u color\u derivation,inplace=True,升序=True)”来表示这一点那么,为什么要绘制大数据帧而不是所有帧呢?对不起,谢谢,这是问题描述中的错误,您使用升序=真进行排序,这意味着最小的值被移动到数据帧的第一行。请尝试
ascending=False
Hi Johan,多亏了你的帖子,我发现了错误:我必须使用“colormap=”which map“,而不是“colormap.colors”,然后输出与预期一致。