【发布时间】:2020-10-05 16:54:08
【问题描述】:
我有一系列测量值,我想绘制为 pandas.plotting.parallel_coordinates,其中每条线的颜色由一个 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_for_line_color_derivation”的值来影响堆叠线条的顺序。到目前为止,我还没有找到方法。
【问题讨论】:
-
我的猜测是它们可能是按照它们在数据框中出现的顺序绘制的。您是否尝试按相关列对数据框进行排序?
-
嗨,保罗,是的,我这样做了 - 试图通过“allFrames.sort_values(column_for_line_color_derivation, inplace=True, ascending=True)”这一行来表明这一点
-
那你为什么要绘制
largeDataFrame而不是allFrames? -
抱歉 - 谢谢 - 这是问题描述中的错误
-
您使用
ascending=True进行排序,这意味着将最小值移动到数据框的第一行。试试ascending=False
标签: python pandas matplotlib parallel-coordinates