matplotlib / matplotlib/matplotlib

[MNT]: Unite property cycles for lines and patches

Open
#29,468 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Maintenance
Dominant language
Python
Stars
23.2k
Forks
8.5k
Avg merge
1d 6h
Merged PRs (30d)
66

Description

### Summary

Loosely insprired by #19479.

We have separate property cycles for lines and patches. This is a source of confusion and IMHO doesn't give a benefit.

### Proposed fix

Unite the property cycles so that an Axes has just one cycle to draw from, no matter what the Artist is.

- Most simple plots use only either lines or patches. They wouldn't know the difference.
- If plots have both lines and patches, e.g. one line, one bar plot, IMHO it's more clear to by default use different colors.
- It's quite unlikely that people implicitly rely on synced colors to intentionally have parallelism between the lines and colors.

Migration:
- Add/document a way to get the state of the next element in *the* cycle (as long as there are two, use the line cycle). This will enable explicit use of a cycle element for multiple artists like this:
```
prop = ax.prop_cycle_next()
ax.plot(..., color=prop['color'])
ax.bar(... color=prop['color'])
```
- Maybe consider ways to feed a cycle element back into a plotting function, either through an explicit kwarg `ax.plot(..., prop=prop)`, or by ensuring that the cycle element can be dict-unpacked `ax.plot(..., **prop)`.
- Minimal announce this as upcoming change in the release notes. If people are relying on parallel cycles they should move to the above pattern.
- We could also detect when both cyclers are used and issue a warning. The downside is that people will get a warning as soon as they use a mixture of lines and patches and they may be ok with the new behavior (it's unlikely they really intend to use the old behavior).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the issue and the related discussion in #19479, then locate Matplotlib's separate property-cycle handling for lines and patches. Define how one shared cycle and explicit reuse of a cycle element should work, including migration and release-note implications; the unresolved API alternatives indicate design work before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.