Skip to content

CN colors look up the global prop_cycle at draw time rather than the axes' one. #9842

Closed

Description

@anntzer

Bug report

Bug summary

http://matplotlib.org/devdocs/tutorials/colors/colors.html states that

a “CN” color spec, i.e. 'C' followed by a single digit, which is an index into the default property cycle (matplotlib.rcParams['axes.prop_cycle']); the indexing occurs at artist creation time and defaults to black if the cycle does not include color.

In particular, this implies that the lookup is not performed on the Axes' prop_cycle (but the global one), which is the actual behavior, may be a bit strange but I guess is OK.
On the other hand, the look up definitely occurs at draw time and not at artist creation time:

Code for reproduction

from pylab import *

gca().set_axis_off()
l, = plt.plot([1, 2], c="C0")
rcParams["axes.prop_cycle"] = cycler(color=["r", "g", "b"])
print(l.get_color())
show()

Actual outcome

outputs 'C0' and a red line, not a tab:blue one.

Expected outcome

We need to discuss whether the doc is wrong or the behavior is wrong...

Matplotlib version

  • Operating system:
  • Matplotlib version: master (there was some refactoring in New color conversion machinery. #6382 but looking at the diff it is clear that the current behavior was already present earlier).
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:

Activity

  1. github-actions commented on Apr 25, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  2. tacaswell commented on Apr 25, 2023

    @tacaswell
    Member

    The docs are wrong, at the time we resolve 'CN', we have no way of knowing what Axes we are going to be associated with.

  3. QuLogic commented on Apr 26, 2023

    @QuLogic
    Member

    The docs say "at draw time" and have done so since #12598.

  4. added this to the v3.1.0 milestone on Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions