matplotlib / matplotlib/cycler
Allow getitem from a cycler
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 83
- Forks
- 51
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the cycler implementation and its existing tests, focusing on how cycles are iterated and how their length is exposed. Add indexing with the requested modulo behavior, and update tests to show that mycycler[i] returns the item at i % len(mycycler).
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100