-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Bug report
Bug summary
imshow
pixel boundaries visibly shift from expected coordinates by many pixels when zooming in, depending on dpi but not improving at high dpi.
I am trying to plot gridded data with imshow
so it aligns with other plot elements like lines. When I zoom in on the image so image pixels are bigger than the plot axes, the boundaries between pixels are visibly shifted from where they ought to be. The shift depends on the dpi of the figure but cannot be resolved by changing the dpi.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
dpi=72
plt.figure(figsize=(12,4), dpi=dpi)
z = np.eye(2)
for ii, d in enumerate([1, .1, .01]):
plt.subplot(1,3,ii+1)
plt.imshow(z)
plt.xlim([0.5-d, 0.5+d])
plt.ylim([0.5-d, 0.5+d])
plt.vlines([-.5, 0.5, 1.5, 2.5, 3.5], -.5, 3.5, 'r')
plt.hlines([-.5, 0.5, 1.5, 2.5, 3.5], -.5, 3.5, 'r')
plt.title([f"Full image ({dpi} dpi)", "10x", "100x"][ii])
Actual outcome
Several results with different dpi. Screenshotted at same resolution because one of them was generated at 1000 dpi.
Expected outcome
The red grid lines drawn with vlines
and hlines
should lie directly on pixel boundaries.
Matplotlib version
Mac OS X 10.12.6
Matplotlib version 3.0.3 installed from pip I think.
Backend: module://ipykernel.pylab.backend_inline
Python 3.7