Reset color cycle in Matplotlib

前端 未结 6 1088
北恋
北恋 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:27

    You can get the colors from seaborn like this: colors = sns.color_palette(). Ffisegydd's answer would then work great. You could also get the color to plot using the modulus/remainder operater (%): mycolor = colors[icolumn % len(colors]. I use often use this approach myself. So you could do:

    for icol, column in enumerate(with_transaction_frame.columns): mycolor = colors[icol % len(colors] ax.plot(with_transaction_frame[col], label=col, alpha=1.0, color=mycolor)

    Ffisegydd's answer may be more 'pythonic', though.

提交回复
热议问题