Skip to content

πŸš€ New Release: Configurator Handler Registration

Choose a tag to compare

@cvanelteren cvanelteren released this 13 Oct 13:38
· 4179 commits to main since this release

This release introduces a powerful extension point to the configuration system β€” Configurator.register_handler() β€” enabling dynamic responses to configuration changes.

✨ New Feature: register_handler

You can now register custom handlers that execute automatically when specific settings are modified.
This is particularly useful for settings that require derived logic or side-effects, such as updating related Matplotlib parameters.

register_handler(name: str, func: Callable[[Any], Dict[str, Any]]) β†’ None

Example (enabled by default):

def _cycle_handler(value):
    # Custom logic to create a cycler object from the value
    return {'axes.prop_cycle': new_cycler}

rc.register_handler('cycle', _cycle_handler)

Each handler function receives the new value of the setting and must return a dictionary mapping valid Matplotlib rc keys to their corresponding values. These updates are applied automatically to the runtime configuration.


🧩 Why It Matters

This addition:

  • Fixes an issue where cycle: entries in ultraplotrc were not properly applied.
  • Decouples configuration logic from Matplotlib internals.
  • Provides a clean mechanism for extending the configuration system with custom logic β€” without circular imports or hard-coded dependencies.

πŸ”§ Internal Improvements

  • Refactored configuration update flow to support handler callbacks.
  • Simplified rc management by delegating side-effectful updates to registered handlers.

πŸ’‘ Developer Note

This API is designed to be extensible. Future handlers may include dynamic color normalization, font synchronization, or interactive theme updates β€” all powered through the same mechanism.