Add highlight marker support for plot/scatter API in SVG backend#31345
Add highlight marker support for plot/scatter API in SVG backend#31345wuyao1997 wants to merge 9 commits intomatplotlib:mainfrom
Conversation
Import RendererSVG within a function to improve encapsulation.
Remove unnecessary blank line in draw_markers function.
|
Thanks for the PR. However, we must handle such a change more systematically. Adding highlight info to For maintainability, I'm not willing to accept Under these constraints, the problem is much harder. A solution strategy would be
While this is doable, the first two points are quite a heavy lift, and I'm inclined to argue that highlight markers are quite rare and not worth the effort. What would me more valuable, would be a general gradient support, but that's an even more complex topic. You have the above issue, plus a more complex specification at the artist level. |
This PR addresses the long-standing feature request for gradient/highlight-styled markers in Matplotlib's
plotandscatterAPIs, as raised in #8926. Currently, Matplotlib lacks native support for glossy/highlighted marker rendering across backends, with workarounds like post-processing SVG files or using custom images being the only options—both of which have limitations with legend compatibility and ease of use.Implementation Method
This change implements basic highlight marker functionality exclusively for the SVG backend by introducing a dynamic
_highlight_svgmember injected intoLine2D(forplot) andPathCollection(forscatter) classes. The draw methods of these two classes are modified to check for the_highlight_svgflag, and theRendererSVG.draw_markersmethod is updated to render a highlight mask over markers when the flag is set, achieving a glossy highlight effect.Extensibility
The implementation is intentionally minimal and unrefined at this stage, but the core design is backend-agnostic and extensible: the same flag-based injection pattern can be adapted to other backends (e.g., Agg) with backend-specific rendering logic. For the Agg backend, this would require modifications to the underlying C language code for marker drawing, which is left as future work.
Minimum self-contained example
Known issues
A fixed element ID -
_m_overlayGradientis used in the SVG backend, and this content is written to the SVG file regardless of whether the image contains highlighted markers or not.Closes #8926
AI Disclosure
No generative AI tools were used in the development of this PR. All code and documentation were written manually with reference to Matplotlib's existing backend and marker rendering codebase.
PR checklist