Axes.plot produces thin lines (1, 3, ... px) which may snap incorrectly relative to Rectangles depending on the dpi and Axes position, in other words, the width of the left and bottom margins. In such cases, non-snapped lines achieve the desired outcome.
The Axes relative position of (0.09, 0.1) is chosen on purpose so that the left margin is 0.09 * 10 in * 155 dpi = 139.5 px and the bottom one is 155 px. Also note that the Axis are scaled to be 1 pixel : 1 unit.
Actual outcome
Zoom in to view individual pixels...
Expected outcome
That the lime line snaps correctly in the middle of the blue Rectangles. Note how the horizontal non-snapped red line works as desired.
Feature request
To implement something equivalent to snapx and snapy following scalex and scaley trend. #15595 might change this trend though. This feature could be used to work around this issue, but I think the solutions should be independent. Will split this request into another issue if it's welcomed.
changed the title [-]Line2D snaps incorrectly relative to Rectangle and request snap(x)(y) parameters[/-][+]Line2D can snap incorrectly and request snap(x)(y) parameters[/+]on Dec 4, 2020
It's not clear we can do anything about it? The point of snapping is that there is a critical value below which everything gets snapped to one pixel row, and above which everything gets snapped to the next pixel row...
Please unsuscribe me , from all the matplotlib mails.
Thanks
Enviado desde Correo para Windows 10
De: Thomas A Caswell
Enviado: martes, 29 de diciembre de 2020 14:25
Para: matplotlib/matplotlib
CC: Subscribed
Asunto: Re: [matplotlib/matplotlib] Line2D can snap incorrectly and request snap(x)(y) parameters (#19054)
xref #8265 for discussion and some code on floor vs round.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
I'm going to close, in the same spirit as #18945. Numbers right on the border of 0.5 are going to flop between either side arbitrarily, based on round off error.
@Ernesto1971 we can't change your subscription status on GitHub. You have to do that yourself.
@timhoffm I think this is more than a numeric issue. @anntzer I found the thresholds and there are still some unanswered questions... The below thresholds are between the bottom/left pixel row/column and middle pixel row/column of the original blue cross for the x and y axis:
x (offsetting the vertical artists):
rectangle: left column < 801.0 <= middle column
snapped line: left column < 801.0 <= middle column
normal line: left column < ~801.5 < middle column (threshold determines where most of the opacity will be)
@jklymak Even if we ignore the exact transition points (<= or <), bizarre snapping still occurs:
Why are the thresholds between snapped and not snapped artists for both axis offset by half? Based on Artist.set_snap, 1px lines between 2 pixels should be interpolated between them for not snapped lines. Since the same x or y value/region that maps to a pixel border (causing interpolation) could be used for both line types, why does the snapped line not interpret this same value as a threshold/border?
The x thresholds are offset from the y thresholds by +0.5, except the snapped line threshold, which is offset by -0.5, why? Furthermore, this causes the absurd case where a line at y=801.5 would be drawn outside a rectangle between y=801 and y=803.
Activity
timhoffm commented on Dec 28, 2020
This is a numeric issue. If you replace the 801.5 y-values by 801.50000000001 everything looks right, i.e.
I'm not clear if we can do anything about this.
anntzer commented on Dec 29, 2020
It's not clear we can do anything about it? The point of snapping is that there is a critical value below which everything gets snapped to one pixel row, and above which everything gets snapped to the next pixel row...
tacaswell commented on Dec 29, 2020
xref #8265 for discussion and some code on floor vs round.
Ernesto1971 commented on Dec 30, 2020
jklymak commented on Dec 30, 2020
I'm going to close, in the same spirit as #18945. Numbers right on the border of 0.5 are going to flop between either side arbitrarily, based on round off error.
@Ernesto1971 we can't change your subscription status on GitHub. You have to do that yourself.
alexiscoutinho commented on Mar 9, 2021
@timhoffm I think this is more than a numeric issue. @anntzer I found the thresholds and there are still some unanswered questions... The below thresholds are between the bottom/left pixel row/column and middle pixel row/column of the original blue cross for the x and y axis:
x (offsetting the vertical artists):
rectangle: left column < 801.0 <= middle column
snapped line: left column < 801.0 <= middle column
normal line: left column < ~801.5 < middle column (threshold determines where most of the opacity will be)
y (offsetting the horizontal artists):
rectangle: bottom row <= 800.5 < middle row
snapped line: bottom row <= 801.5 < middle row
normal line: bottom row < ~801.0 < middle row
@jklymak Even if we ignore the exact transition points (<= or <), bizarre snapping still occurs: