Skip to content

[MNT]: Color normalization in GraphicsContextBase #31105

Description

@timhoffm

Summary

We have

class GraphicsContextBase:

    def set_foreground(self, fg, isRGBA=False):
        """
        Set the foreground color.

        Parameters
        ----------
        fg : :mpltype:`color`
        isRGBA : bool
            If *fg* is known to be an ``(r, g, b, a)`` tuple, *isRGBA* can be
            set to True to improve performance.
        """

It feels unnecessary and like a mental burden to handle unnormalized colors the GraphicsContext. Flexible color names is primarily a user-facing topic; and maybe (t.b.d.) an artist topic so that they can reproduce a color exactly as it was specified by the user (a.set.color(c); a.get_color == c). But I think the GraphicsContext should not need to bother with this. It should only need rgba information.

Possible improvement:

  • Discourage isRGBA=False
  • internally only use isRGBA=True
  • At some point deprecatee the isRGBA argument and remove (as part of general backend API evolution).

Semi-OT: is set_foreground the right abstraction or should we rather have set_rgba() and discorage set_foreground? Related: #31094 (comment)

Proposed fix

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions