pandas有两个带有时间框架的date和timeseries列。在
TOTAL.PAPRPNT.M Label
1973-03-01 25504.000 3
1973-04-01 25662.000 3
1973-05-01 25763.000 0
1973-06-01 25996.000 0
1973-07-01 26023.000 1
1973-08-01 26005.000 1
1973-09-01 26037.000 2
1973-10-01 26124.000 2
1973-11-01 26193.000 3
1973-12-01 26383.000 3
如您所见,每个数据集对应一个“标签”。如果从上一个“点”到下一个“点”的直线具有某些特征(不同类型的股票图变化),因此,对于这些图中的每一个都使用单独的颜色,则该标签基本上应进行分类。这个问题与这个问题Plot Multicolored line based on conditional in python有关,但是“groupby”部分完全忽略了我的理解,这个方案是双色方案,而不是多色方案(我有四个标签)。在
我想根据与dataframe中每个条目相关联的标签创建一个多色图。在
这是一个我认为你想做什么的例子。它基于评论中提到的MPL文档,使用随机生成的数据。 只需将colormap边界映射到由类数给定的离散值。在
每个线段都根据
df['Label']
中给出的类标签来着色。下面是一个示例结果:相关问题 更多 >
编程相关推荐