假设我有一个这样的系列:
testdf = pd.Series([3, 4, 2, 5, 1, 6, 10])
绘图时,结果如下:
testdf.plot()
我想将前 4 个值之前的线条绘制为蓝色(默认),将线条的其余部分绘制为红色。我该怎么做?
最佳答案
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')
关于python - 如何用不同颜色绘制同一 Pandas Series 列的不同部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47478506/