Description
Bug report
Bug summary
Axes.plot
produces thin lines (1, 3, ... px) which may snap incorrectly relative to Rectangle
s 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.
Code for reproduction
from matplotlib.pyplot import figure
from matplotlib.patches import Rectangle
fig = figure(figsize=(10,10), dpi=155)
ax = fig.add_axes([0.09, 0.1, 0.8, 0.86])
ax.axis([0, 1240, 0, 1333])
ax.minorticks_on()
ax.grid(which='both', ls=':')
ax.add_patch(Rectangle((700,800), 200, 3, snap=True))
ax.add_patch(Rectangle((800,700), 3, 200, snap=True))
lw = 1 * 72 / 155
ax.plot([890,801.5,801.5], [801.5,801.5,890], c='lime', lw=lw, snap=True)
ax.plot([710,801.5,801.5], [801.5,801.5,710], c='red', lw=lw, snap=False)
fig.savefig("snap.png")
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 Rectangle
s. 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.
Matplotlib version
- Operating system: Windows 10
- Matplotlib version: 3.3.3
- Matplotlib backend: module://ipykernel.pylab.backend_inline
- Python version: 3.9.0
Python installed via official installer. Matplotlib installed via pip.