utils.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:faampy 作者: ncasuk 项目源码 文件源码
def freeze_color_cycle(ax):
    """A function that freezes the color cycle. This is useful for example when
    the twinx() command is used and the color cycle would normally be reseted.

    Usage:

    import matplotlib.pyplot as plt
    import numpy as np

    plt.close('all')
    for i in range(3):
        plt.plot(np.random.random(20))

    ax=plt.gca()
    cc=freeze_color_cycle(ax)
    plt.twinx()
    ax=plt.gca()
    ax.set_color_cycle(cc)

    #plot some more on the new twined axes
    for i in range(3):
        plt.plot(np.random.random(20))

    #When we set-up a new figure we start with blue again
    fig=figure()
    for i in range(3):
        plot(np.random.random(20))

    """
    import matplotlib as mpl
    if mpl.__version__  >= '1.5.1':
        next_color=ax._get_lines.prop_cycler.next()['color']
    else:
        next_color=next(ax._get_lines.color_cycle)

    ix=plt.rcParams['axes.color_cycle'].index(next_color)
    color_cycle=plt.rcParams['axes.color_cycle'][ix:]+plt.rcParams['axes.color_cycle'][:ix]

    return color_cycle
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号