How to plot different parts of same Pandas Series

2019-07-19 17:39发布

This question already has an answer here:

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条回答
Root(大扎)
2楼-- · 2019-07-19 17:46

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

查看更多
登录 后发表回答