Skip to content

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

Closed
@anntzer

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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions