Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e5a38a

Browse files
committed
Merge pull request #1150 from leejjoon/fix-image-shift
the affine matrix is calculated in the display coordinate for interpolation='none'
2 parents ed7db9b + 67eb71d commit 2e5a38a

4 files changed

Lines changed: 228 additions & 6 deletions

File tree

lib/matplotlib/image.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# the image namespace:
2626
from matplotlib._image import *
2727

28-
from matplotlib.transforms import BboxBase, Bbox
28+
from matplotlib.transforms import BboxBase, Bbox, IdentityTransform
2929
import matplotlib.transforms as mtransforms
3030

3131

@@ -270,8 +270,8 @@ def _draw_unsampled_image(self, renderer, gc):
270270
# firs, convert the image extent to the ic
271271
x_llc, x_trc, y_llc, y_trc = self.get_extent()
272272

273-
xy = trans.transform_non_affine(np.array([(x_llc, y_llc),
274-
(x_trc, y_trc)]))
273+
xy = trans.transform(np.array([(x_llc, y_llc),
274+
(x_trc, y_trc)]))
275275

276276
_xx1, _yy1 = xy[0]
277277
_xx2, _yy2 = xy[1]
@@ -283,15 +283,16 @@ def _draw_unsampled_image(self, renderer, gc):
283283
if self._image_skew_coordinate:
284284
# skew the image when required.
285285
x_lrc, y_lrc = self._image_skew_coordinate
286-
xy2 = trans.transform_non_affine(np.array([(x_lrc, y_lrc)]))
286+
xy2 = trans.transform(np.array([(x_lrc, y_lrc)]))
287287
_xx3, _yy3 = xy2[0]
288288

289289
tr_rotate_skew = self._get_rotate_and_skew_transform(_xx1, _yy1,
290290
_xx2, _yy2,
291291
_xx3, _yy3)
292-
trans_ic_to_canvas = tr_rotate_skew+trans.get_affine()
292+
trans_ic_to_canvas = tr_rotate_skew
293293
else:
294-
trans_ic_to_canvas = trans.get_affine()
294+
trans_ic_to_canvas = IdentityTransform()
295+
295296

296297
# Now, viewLim in the ic. It can be rotated and can be
297298
# skewed. Make it big enough.
5.4 KB
Binary file not shown.
Lines changed: 206 additions & 0 deletions
Loading

lib/matplotlib/tests/test_image.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ def test_no_interpolation_origin():
160160
ax = fig.add_subplot(212)
161161
ax.imshow(np.arange(100).reshape((2, 50)), interpolation='none')
162162

163+
@image_comparison(baseline_images=['image_shift'], remove_text=True,
164+
extensions=['pdf', 'svg'])
165+
def test_image_shift():
166+
from matplotlib.colors import LogNorm
167+
168+
imgData = [[1.0/(x) + 1.0/(y) for x in range(1,100)] for y in range(1,100)]
169+
tMin=734717.945208
170+
tMax=734717.946366
171+
172+
fig = plt.figure()
173+
ax = fig.add_subplot(111)
174+
ax.imshow(imgData, norm=LogNorm(), interpolation='none',
175+
extent=(tMin, tMax, 1, 100))
176+
ax.set_aspect('auto')
177+
163178
if __name__=='__main__':
164179
import nose
165180
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

Comments
 (0)