def keep_color(ax=None):
    ''' Keep the same color for the same graph. 
    Warning: due to the structure of Python iterators I couldn't help but
    iterate over all the cycle twice. One first time to get the number of elements
    in the cycle, one second time to stop just before the last. And this still 
    only works assuming your cycle doesn't contain the object twice

    Note: when setting color= it looks like the color cycle state is not called

    TODO: maybe implement my own cycle structure '''

    if ax is None:
        ax = mpl.pyplot.gca()

    i = 1  # count number of elements
    cycle = ax._get_lines.prop_cycler
    a = next(cycle)     # a is already the next one.
    while(a != next(cycle)):
        i += 1
    # We want a-1 to show up on next call to next. So a-2 must be set now
    for j in range(i - 2):
        next(cycle)
Keep the same color for the same graph. 
    Warning: due to the structure of Python iterators I couldn't help but
    iterate over all the cycle twice. One first time to get the number of elements
    in the cycle, one second time to stop just before the last. And this still 
    only works assuming your cycle doesn't contain the object twice

    Note: when setting color= it looks like the color cycle state is not called

    TODO: maybe implement my own cycle structure