0

I have the following pandas dataframe, and I want to have a line plot that the first 10 points are colored different from the rest.

df = [

    A           B  
2017-05-01    31.98
2017-05-02    31.
2017-05-03    30.41
2017-05-04    29.
2017-05-05    29.
2017-05-06    28.48
2017-05-07    27.73
2017-05-08    26.
2017-05-09    26.29
2017-05-10    27.
2017-05-11    28.56
2017-05-12    30.
2017-05-13    31.66
2017-05-14    33.
2017-05-15    35.67
2017-05-16    38.
2017-05-17    40.59
2017-05-18    43.
2017-05-19    46.42
2017-05-20    49.68
2017-05-21    53.
]

I tried to do it in matplotlib, like

plt.plot(df[B][:11])
plt.plot(df[B][11:])
plt.show()

but I got two different lines in one figure. I want a continuous line with two different colors, instead. I read similar question in this link, but I couldn't implement it.

mk_sch
  • 1,060
  • 4
  • 16
  • 31

1 Answers1

1

I think this is what you want:

df.A = pd.to_datetime(df.A)

plt.plot(df.A[:11], df.B[:11])
plt.plot(df.A[10:], df.B[10:])

plt.xticks(rotation=45)

plt.show()
Bonifacio2
  • 3,405
  • 6
  • 34
  • 54