我试图在列中绘制值,并通过从外部手动传递颜色来根据不同列中的组对它们进行着色。我将蓝色分配给测试组,将红色分配给训练组。但以下代码仅以蓝色绘制值。
import datetime
import pandas as pd
dft2 = pd.DataFrame({'A': [1,3,3,4,1,3,3,4],
'B': [2015, 2016, 2017,2018, 2019, 2020, 2021, 2022],
'C': pd.Categorical(["test", "train", "test", "train","train","train","train","train"])})
dft2 = dft2.set_index('B')
colors = {'test': 'b', 'train': 'r'}
dft2['A'].plot(figsize=(24,3), rot=90, color=[colors[i] for i in dft2['C']])
www说
相关分类