【问题标题】:How to plot different parts of same Pandas Series column with different colors? [duplicate]如何用不同颜色绘制同一 Pandas Series 列的不同部分? [复制]
【发布时间】:2018-05-08 18:39:48
【问题描述】:

假设我有一个这样的系列:

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

绘图时,结果如下:

testdf.plot()

我想用蓝色(默认)绘制前 4 个值的线,用红色绘制线的其余部分。我该怎么做?

【问题讨论】:

    标签: python python-3.x pandas matplotlib plot


    【解决方案1】:

    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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      相关资源
      最近更新 更多