-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Bug summary
When using imshow() with a small array (large pixels), the pixel patches can end up slightly misaligned. This becomes especially obvious when thin grid lines are overlaid on the figure.
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
fig,ax = plt.subplots()
N = 12
ax.imshow(np.random.rand(N, N))
seps = np.arange(-0.5, N)
ax.vlines(seps, -0.5, N - 0.5, linewidth=1)
ax.hlines(seps, -0.5, N - 0.5, linewidth=1)
plt.show()Actual outcome
Expected outcome
A figure where none of the pixel patches overlap their respective grid lines.
Additional information
I originally thought this was the same issue as #14143, see my original comment. Eventually that bug was fixed but this issue remained. To quote @ayshih:
Based on my investigation so far, the problem in your example is indeed distinct from the original issue, and it is very important to fix. It's not a bug internal to the image-resampling code, but rather it has to do with how image placement affects what resampling is requested and how the resampled image is drawn.
Operating system
Debian
Matplotlib Version
3.11.0.dev1652+gddd4196c7 (but first found around 3.3.0)
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
uv