Reset color cycle in Matplotlib

前端 未结 6 1090
北恋
北恋 2020-11-27 04:12

Say I have data about 3 trading strategies, each with and without transaction costs. I want to plot, on the same axes, the time series of each of the 6 variants (3 strategi

6条回答
  •  没有蜡笔的小新
    2020-11-27 04:49

    As an addition to the already excellent answers, you can consider using a colormap:

    import matplotlib.pyplot as plt
    import numpy as np
    
    cmap = plt.cm.viridis
    
    datarange = np.arange(4)
    
    for d in datarange:
        # generate colour by feeding float between 0 and 1 to colormap
        color = cmap(d/np.max(datarange)) 
        plt.plot(np.arange(5)+d, c=color)
    
    for d in datarange:
        # generate colour by feeding float between 0 and 1 to colormap
        color = cmap(d/np.max(datarange))
        plt.plot(-np.arange(5)+d, c=color)
    

提交回复
热议问题