How to plot different parts of same Pandas Series column with different colors?

Viewed 344

Let's say I have a Series like this:

testdf = pd.Series([3, 4, 2, 5, 1, 6, 10])

When plotting, this is the result:

testdf.plot()

Plot

I want to plot, say, the line up to the first 4 values in blue (default) and the rest of the line in red. How can I do it?

1 Answers

IIUC

import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)
testdf.plot(ax=ax,color='b')
testdf.iloc[3:].plot(ax=ax,color='r')

enter image description here

Related