Skip to content

[MNT]: Collect style properties in a dedicated object #30828

Open

Description

@timhoffm

Summary

Current situation

Currently, style information is directly attached to the Artist classes, i.e. mixed with data, metadata (e.g. gid, label) and drawing information (e.g. animated, zorder).

Proposal

I prose to collect the style information in a dedicated container, e.g. a dataclass, that will be a member of the Artist.

Feedback welcome!

Motivation

Similar how the data prototype collects and abstracts data handling, an ArtistStyle collects all visual aspects of the Artist. This creates internal semantic structures: While Artists currently contain a long ist of artist properties with various purposes, we may simplify them by grouping properties by concerns. I anticipate that this will make it easier to reason about them. Also this can enable new features like multiple artists sharing styles, or dynamic style updates.

Additional information

For a start, this would be an internal change, without any modification to the public Artist API.

As an example, I could see the following Line2D properties grouped into a style:

  • alpha
  • antialiased
  • color or c
  • dash_capstyle
  • dash_joinstyle
  • dashes
  • drawstyle
  • fillstyle
  • gapcolor
  • linestyle
  • linewidth
  • marker
  • markeredgecolor
  • markeredgewidth
  • markerfacecolor
  • markerfacecoloralt
  • markersize
  • markevery
  • path_effects
  • rasterized
  • sketch_params
  • snap
  • solid_capstyle
  • solid_joinstyle

This would reduce the non-stype properties to:

  • animated
  • clip_box
  • clip_on
  • clip_path
  • data
  • figure
  • gid
  • in_layout
  • label
  • mouseover
  • picker
  • pickradius
  • transform
  • url
  • visible
  • xdata
  • ydata
  • zorder

Proposed fix

No response

Activity

  1. story645 commented on Dec 9, 2025

    @story645
    Member

    I'm roughly for separating out the styling from the behavior b/c I think it's a prerequisite to serialization (it's also loosely tied to mep 26) and cleaning up the style sheets/style sheets docs. There was a bit of a discussion on one of the calls about protocols vs classes that might also apply here.

    When I've looked into this, roughly the parameter families map to the mark types/base artist classes - point (unfilled marker), line (Line2D), area (Patch, which contains Line2D for edge) - which I think can be roughly specified as protocols/classes & then any artist specific styling can be specified as an add on. Making the composition explicit would also probably make it easier to sort out which style parameters can be shared.

    Attn @ksunden b/c a good chunk of the prototype work is new artists.

  2. DipayanDasgupta commented on Dec 10, 2025

    @DipayanDasgupta

    Hi @timhoffm,

    I have opened a Draft PR (#30832) with a proof-of-concept implementation for this proposal.

    In the prototype, I introduced a LineStyle dataclass within lines.py and refactored Line2D to store the linewidth property inside this style object instead of directly on the instance (self._style.linewidth vs self._linewidth).

    This demonstrates that we can group style properties internally while maintaining full backward compatibility with the existing public API (getters/setters). I would appreciate any feedback on this approach before expanding it to other properties.

  3. timhoffm commented on Dec 10, 2025

    @timhoffm
    MemberAuthor

    @DipayanDasgupta thanks for your interest in contributing. However, you're jumping to action way too quickly. That one can internally group attributes into a dataclass is clear and does not need a demonstration.
    The first question is whether we want to follow this approach, and if so, how exactly (c.f. @story645's post). The main task here is architecture, and that requires carefully analyzing the topic and making the right design decisions. Implementation itself will be fairly straight forward, once we know exactly what we want.

  4. DipayanDasgupta commented on Dec 10, 2025

    @DipayanDasgupta

    Thanks for the course correction, @timhoffm . I took a step back to analyze the architectural implications here, particularly regarding shared state and serialization as mentioned by @story645 . If the goal is enabling multiple artists to share styles with dynamic updates, the primary challenge isn't really the storage itself but rather the cache invalidation or observability. Since the current implementation immediately sets the stale flag on the artist when a property changes, moving state to a passive dataclass means we lose that trigger. To support shared styles where modifying one object updates multiple artists, we essentially need an observer pattern.

    I think the robust path forward combines composition with an active observer model. Building on the earlier point about protocols, instead of a monolithic style object, we could compose artists from semantic units like a StrokeStyle for lines and edges or a FillStyle for patches. This creates a reusable schema where a Line2D holds a StrokeStyle and a Rectangle holds both a StrokeStyle and a FillStyle. To handle the updates without memory leaks, these style containers could implement a lightweight publisher-subscriber model using weak references to notify registered artists when a value changes. We would also need to decide if the style object holds strict explicit values or fully resolved values from rcParams. If this aligns with the vision, the first step would be defining that class structure and invalidation mechanism rather than refactoring the specific artists immediately.

  5. story645 commented on Dec 10, 2025

    @story645
    Member

    @DipayanDasgupta while I appreciate your enthusiasm, I really think @ksunden needs to chime in as he's been working on new artists for a couple of years now.

  6. timhoffm commented on Jan 26, 2026

    @timhoffm
    MemberAuthor

    Note to self: Overall one can classify the state of an artist (i.e. contents of self.__dict__) into the following categories:

    • style properties
    • other poperties, e.g. pick_radius, mouseover, url, gid
    • data: xdata, ydata
    • internal state

    Idea: Stucture / group the state:

    • data moves to the data container
    • style moves to a dedicated object (separate appearance from contents - conceptually similar to CSS)
    • for now we are left with a zoo of remaining state in self.__dict__ - it may be possible to split another concept from it, but there are border cases so that a complete partition into topics may be difficult. Let's not do too much at a time.

    Artist properties set_* are need for categories 1-3 (i.e. everything except internal state). They remain the public interface and should dispatch internally to the respective state; e.g. set_linestyle will go to self._style.linestyle instead of self._linestyle.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions