Plotting line with different colors

前端 未结 2 1574
感情败类
感情败类 2021-01-24 11:51
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df1 = pd.DataFrame(np.random.randint(0,15,size=(15, 1)))
df2 = pd.DataFrame(np.random.randint(20,         


        
2条回答
  •  孤城傲影
    2021-01-24 12:51

    What about

    #[...]
    df3 = result.cumsum()
    df3 = df3.reset_index(drop=False)
    plt.plot(df3.mask(df3.apply(lambda x: x.index < 15))[0], color='blue')
    plt.plot(df3.mask(df3.apply(lambda x: x.index > 15))[0], color='green')
    plt.show()
    plt.close()# do not forget this to save you from Runtime Error.
    

提交回复
热议问题