Assign line colors in pandas

后端 未结 2 687
小蘑菇
小蘑菇 2020-12-19 05:55

I am trying to plot some data in pandas and the inbuilt plot function conveniently plots one line per column. What I want to do is to manually assign each line a color based

2条回答
  •  时光取名叫无心
    2020-12-19 06:12

    Try:

    df.plot(color = s.values)
    

    this will assign the colors no matter the scale of the index.

    EDIT:

    I tried with three columns:

    df = pd.DataFrame({'1': [1, 2, 3, 4], '2': [1, 2, 1, 2], '3': [4, 3, 2, 1]})
    s = pd.Series(['c','y','r'], index=[1,3,2])
    df.plot(color = s.sort_index().values)
    

    and sorting the Series it works.

提交回复
热议问题