Skip to content

Allow getitem from a cycler #27

Description

@tritemio

It would be useful to add __getitem__ functionality to cycler.

The use case is a "crowded" for loop where you want to get the cycler style without using a loop variable. Something like:

data_cycler = cycler('alpha', (0.2, 0.4, 0.6)) + cycler('color', ('r', 'g', 'b'))
fit_cycler = cycler('color', ('k', 'm', 'orange'))

for i, (data, fit) in enumerate(zip(data_list, fit_list)):
    ...
    plt.plot('x', 'y', data=data, data_cycler[i])
    plt.plot('x', 'y', data=data, fit_cycler[i])
    ...

In this case the index i is computed anyway, so using it for the cyclers would be handy, instead of adding the cycler inside zip().

Ideally mycycler[i] should return the item with index i % len(mycycler).

I haven't looked at the code yet. Would this be possible? Would a PR be welcome?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions