Skip to content

WIP: Prototype for lightweight overlay API (canvas-level-rendering)#31382

Draft
joddeepesh-cloud wants to merge 4 commits intomatplotlib:mainfrom
joddeepesh-cloud:overlay-api-prototype
Draft

WIP: Prototype for lightweight overlay API (canvas-level-rendering)#31382
joddeepesh-cloud wants to merge 4 commits intomatplotlib:mainfrom
joddeepesh-cloud:overlay-api-prototype

Conversation

@joddeepesh-cloud
Copy link
Contributor

@joddeepesh-cloud joddeepesh-cloud commented Mar 25, 2026

Status: Draft prototype for discussion

This PR introduces an initial prototype for a lightweight overlay API in Matplotlib.

The goal of this work is to enable temporary graphical primitives (e.g., lines, rectangles) to be rendered directly on the canvas without requiring full figure redraws.

Current implementation includes:

  • Basic overlay storage in FigureCanvasBase
  • Initial integration with Qt backend (backend_qtagg)
  • Rendering of overlay primitives using QPainter

Design Overview

The overlay API is designed to allow temporary graphical primitives to be drawn independently of the main figure rendering pipeline.

Key design decisions:

  • Overlay elements are stored separately from the main figure state to avoid interfering with standard rendering
  • Rendering is integrated into the backend paint phase (Qt) so overlays are drawn after the main figure
  • The API is intentionally minimal (e.g., add_overlay_line) to allow incremental extension and experimentation

This approach aims to provide a lightweight, backend-consistent mechanism for interactive drawing, avoiding repeated full redraws.

Motivation

Interactive tools in Matplotlib (e.g., crosshair cursors, selection boxes, measurement guides) often require temporary graphics that are frequently updated. Currently, these workflows rely on full redraws or workarounds, which can impact performance and increase implementation complexity.

This prototype explores a cleaner approach by introducing a dedicated overlay layer.

Notes

This is an early prototype intended for discussion and feedback. The design and API are subject to change.

This work is part of my GSoC 2026 proposal under NumFOCUS, and I would greatly appreciate feedback on the design direction and integration approach.

@scottshambaugh
Copy link
Contributor

scottshambaugh commented Mar 25, 2026

I'm going to mark this as draft since it's a prototype. Some explanation of the API choices and the resulting capability will help greatly with the discussion

@scottshambaugh scottshambaugh marked this pull request as draft March 25, 2026 18:42
@joddeepesh-cloud
Copy link
Contributor Author

Thanks for taking a look and marking this as draft.

I agree that the API design needs more explanation. I will update the PR description to clarify the design decisions, intended use cases, and how this integrates with the backend rendering pipeline.

This is an early prototype as part of my GSoC proposal, and I’d really appreciate feedback on the overall direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants