8000 Patches eagerly resolve colors and apply alpha, but should do so lazily like Line2Ds · Issue #11710 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Patches eagerly resolve colors and apply alpha, but should do so lazily like Line2Ds #11710
Open
@anntzer

Description

@anntzer

Consider the following example:

from matplotlib.pyplot import Line2D, Rectangle

l = Line2D([], [], alpha=.5)
l.set_color("red")
print(l.get_color())

r = Rectangle((0, 0), 1, 1, alpha=.5)
r.set_facecolor("red")
print(r.get_facecolor())

The line reports its color as "red", but the rectangle reports it as (1, 0, 0, .5). This is because patches immediately resolve colors and apply alphas; to do so they need to maintain an elaborate dance involving _original_facecolor and _original_edgecolor. Conversely, Line2D doesn't resolve colors eagerly (they just store whatever was passed in), and perform the conversion in draw().

As an other example, consider

from pylab import *
from matplotlib.pyplot import Line2D, Rectangle

ax = gca()
ax.add_artist(Line2D([0, 1], [.5, 1], color="C0"))
ax.add_artist(Rectangle((0, 0), 1, .5, color="C0"))
rcParams["axes.prop_cycle"] = cycler(color=["r", "g", "b"])

show()

This will draw a red line (draw-time resolution is affected by the new prop_cycle), but a blue rectangle (eager resolution uses the original prop_cycle).

I think the behavior of Line2D makes more sense (at least the output of get_facecolor() immediately after a set_facecolor() should be what we set...), this would also avoid issues such as #11702/#11703.

(mpl master and probably since a long time ago)

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: consistencykeepItems to be ignored by the “Stale” Github Action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0