Skip to content

Snap markers to subpixels instead of whole ones#32108

Draft
QuLogic wants to merge 2 commits into
matplotlib:mainfrom
QuLogic:marker-snap
Draft

Snap markers to subpixels instead of whole ones#32108
QuLogic wants to merge 2 commits into
matplotlib:mainfrom
QuLogic:marker-snap

Conversation

@QuLogic

@QuLogic QuLogic commented Jul 23, 2026

Copy link
Copy Markdown
Member

PR summary

We cache the marker for performance, but this causes it to look very pixel-grid aligned, especially if there are multiple in a regular pattern, or they are animated.

Apply the same algorithm as mplcairo noted by @anntzer in #7233, specifically, render and cache the marker in n_subdiv levels in each direction, and pick the closest one for each marker.

Fixes #7233

AI Disclosure

None

PR checklist

QuLogic added 2 commits July 23, 2026 04:39
We cache the marker for performance, but this causes it to look very
pixel-grid aligned, especially if there are multiple in a regular
pattern, or they are animated.

Apply the same algorithm as mplcairo noted by @anntzer in matplotlib#7233,
specifically, render and cache the marker in *n_subdiv* levels in each
direction, and pick the closest one for each marker.

Fixes matplotlib#7233
Comment thread src/_backend_agg.h
Comment on lines +501 to +504
// TODO: Pixel markers *must* be drawn snapped.
auto const& is_pixel_marker = false;
// py_eq(marker_path, PIXEL_MARKER.attr("get_path")())
// && marker_trans == PIXEL_MARKER.attr("get_transform")().cast<agg::trans_affine>();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mplcairo special-cases the pixel marker; I have not checked how that turns out or whether that is necessary.

Comment thread src/_backend_agg.h
Comment on lines +532 to +535
auto marker_path_snapped = PathSnapper{
marker_path_nan_removed,
gc.snap_mode, marker_path.total_vertices(),
points_to_pixels(gc.linewidth)};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% certain we should be snapping here for each of the cached subpixel markers. It affects a lot more test images if we drop this though.

@QuLogic

QuLogic commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

The original issue with current style looks like this:
before
and now looks smoother:
after
and the animation is smoother:
skewedgridqtagg

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.

inaccurate marker positioning in plot()

1 participant