Skip to content
This repository
Browse code

Merge pull request #1150 from leejjoon/fix-image-shift

the affine matrix is calculated in the display coordinate for interpolation='none'
  • Loading branch information...
commit 2e5a38ac3aecb3e3e1fa536e5c690f497ddd0719 2 parents ed7db9b + 67eb71d
Michael Droettboom authored September 05, 2012
13  lib/matplotlib/image.py
@@ -25,7 +25,7 @@
25 25
 # the image namespace:
26 26
 from matplotlib._image import *
27 27
 
28  
-from matplotlib.transforms import BboxBase, Bbox
  28
+from matplotlib.transforms import BboxBase, Bbox, IdentityTransform
29 29
 import matplotlib.transforms as mtransforms
30 30
 
31 31
 
@@ -270,8 +270,8 @@ def _draw_unsampled_image(self, renderer, gc):
270 270
         # firs, convert the image extent to the ic
271 271
         x_llc, x_trc, y_llc, y_trc = self.get_extent()
272 272
 
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)]))
275 275
 
276 276
         _xx1, _yy1 = xy[0]
277 277
         _xx2, _yy2 = xy[1]
@@ -283,15 +283,16 @@ def _draw_unsampled_image(self, renderer, gc):
283 283
         if self._image_skew_coordinate:
284 284
             # skew the image when required.
285 285
             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)]))
287 287
             _xx3, _yy3 = xy2[0]
288 288
 
289 289
             tr_rotate_skew = self._get_rotate_and_skew_transform(_xx1, _yy1,
290 290
                                                                  _xx2, _yy2,
291 291
                                                                  _xx3, _yy3)
292  
-            trans_ic_to_canvas = tr_rotate_skew+trans.get_affine()
  292
+            trans_ic_to_canvas = tr_rotate_skew
293 293
         else:
294  
-            trans_ic_to_canvas = trans.get_affine()
  294
+            trans_ic_to_canvas = IdentityTransform()
  295
+
295 296
 
296 297
         # Now, viewLim in the ic.  It can be rotated and can be
297 298
         # skewed. Make it big enough.
BIN  lib/matplotlib/tests/baseline_images/test_image/image_shift.pdf
Binary file not shown
206  lib/matplotlib/tests/baseline_images/test_image/image_shift.svg
... ...
@@ -0,0 +1,206 @@
  1
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
  2
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
  3
+  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
  4
+<!-- Created with matplotlib (http://matplotlib.sourceforge.net/) -->
  5
+<svg height="432pt" version="1.1" viewBox="0 0 576 432" width="576pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  6
+ <defs>
  7
+  <style type="text/css">
  8
+*{stroke-linecap:square;stroke-linejoin:round;}
  9
+  </style>
  10
+ </defs>
  11
+ <g id="figure_1">
  12
+  <g id="patch_1">
  13
+   <path d="
  14
+M0 432
  15
+L576 432
  16
+L576 0
  17
+L0 0
  18
+z
  19
+" style="fill:#ffffff;"/>
  20
+  </g>
  21
+  <g id="axes_1">
  22
+   <g id="patch_2">
  23
+    <path d="
  24
+M72 388.8
  25
+L518.4 388.8
  26
+L518.4 43.2
  27
+L72 43.2
  28
+z
  29
+" style="fill:#ffffff;"/>
  30
+   </g>
  31
+   <g clip-path="url(#p7ff5b81e1d)">
  32
+    <image height="345.6" id="image1d2c2cd45d" transform="matrix(1.0 0.0 0.0 1.0 0.0 432.0)" width="446.399963379" x="72.0" xlink:href="data:image/png;base64,
  33
+iVBORw0KGgoAAAANSUhEUgAAAGMAAABjCAYAAACPO76VAAAABHNCSVQICAgIfAhkiAAAC1RJREFUeJzdXcGO3DgOfZ3yViXdk81iBsgAM7cF9r63+Yb9qv29/ZwADXS6a6vSc3DJJdEk9SjJ1ckQSGxTtGzzmY+UbFff/Rd4/Q+A3wH8/AB8OAB37wHsAEyYJS13uMoEXSy9Jy37/Eiyq5sAwN3/gNc//gDwLwC/Avg7gAcA7zE76YASjB2Au2z5TvSoObbm7B4wyAt9U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scOiNjcEQXCzx1vM1FY24dK4kw+8OildSS+xWzu3PZOOYN2YelW0zeVygxFsVHB2I+YRLTbYmD0jgu6B37ao9VcPAfk7S2lbcskonYeXjWV/TlRS1r/1LIpXXmjVrPXuD1yDLavXiBm/RIZTb+GwDp1yEg7l1qZaNnltpHcwczSSl0MCKAnZ2jVUWsfmr7aLx/+63ZGNHpijxUHAhidwD1hwAsn8VaKaskdkTxhnZM/9jDBkNMi5l+e14QpTcOj8FfDiKGoaEXF7NdT2uo0q4LR9cSvdWxBS4Q2eqKiZdKwbzTu0tRJ/m6I1re2zbY1y+aIV/YbESnrtu0HfVr7kCkRL1/Upkd6oqK1oqrPT90mgbeW+WFDlqKi/fdWVNxE4e2qKU3ofGwlb6B9jkq2eVHh9cNUVJz9nzq8sOaKN6MoAAAAAElFTkSuQmCC" y="-388.8"/>
  34
+   </g>
  35
+   <g id="matplotlib.axis_1">
  36
+    <g id="xtick_1">
  37
+     <g id="line2d_1">
  38
+      <defs>
  39
+       <path d="
  40
+M0 0
  41
+L0 -4" id="mcb557df647" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
  42
+      </defs>
  43
+      <g>
  44
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="146.014526367" xlink:href="#mcb557df647" y="388.8"/>
  45
+      </g>
  46
+     </g>
  47
+     <g id="line2d_2">
  48
+      <defs>
  49
+       <path d="
  50
+M0 0
  51
+L0 4" id="mdad270ee8e" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
  52
+      </defs>
  53
+      <g>
  54
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="146.014526367" xlink:href="#mdad270ee8e" y="43.2"/>
  55
+      </g>
  56
+     </g>
  57
+    </g>
  58
+    <g id="xtick_2">
  59
+     <g id="line2d_3">
  60
+      <g>
  61
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="223.112976074" xlink:href="#mcb557df647" y="388.8"/>
  62
+      </g>
  63
+     </g>
  64
+     <g id="line2d_4">
  65
+      <g>
  66
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="223.112976074" xlink:href="#mdad270ee8e" y="43.2"/>
  67
+      </g>
  68
+     </g>
  69
+    </g>
  70
+    <g id="xtick_3">
  71
+     <g id="line2d_5">
  72
+      <g>
  73
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="300.211425781" xlink:href="#mcb557df647" y="388.8"/>
  74
+      </g>
  75
+     </g>
  76
+     <g id="line2d_6">
  77
+      <g>
  78
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="300.211425781" xlink:href="#mdad270ee8e" y="43.2"/>
  79
+      </g>
  80
+     </g>
  81
+    </g>
  82
+    <g id="xtick_4">
  83
+     <g id="line2d_7">
  84
+      <g>
  85
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="377.309875488" xlink:href="#mcb557df647" y="388.8"/>
  86
+      </g>
  87
+     </g>
  88
+     <g id="line2d_8">
  89
+      <g>
  90
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="377.309875488" xlink:href="#mdad270ee8e" y="43.2"/>
  91
+      </g>
  92
+     </g>
  93
+    </g>
  94
+    <g id="xtick_5">
  95
+     <g id="line2d_9">
  96
+      <g>
  97
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="454.408325195" xlink:href="#mcb557df647" y="388.8"/>
  98
+      </g>
  99
+     </g>
  100
+     <g id="line2d_10">
  101
+      <g>
  102
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="454.408325195" xlink:href="#mdad270ee8e" y="43.2"/>
  103
+      </g>
  104
+     </g>
  105
+    </g>
  106
+   </g>
  107
+   <g id="matplotlib.axis_2">
  108
+    <g id="ytick_1">
  109
+     <g id="line2d_11">
  110
+      <defs>
  111
+       <path d="
  112
+M0 0
  113
+L4 0" id="mc8fcea1516" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
  114
+      </defs>
  115
+      <g>
  116
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="322.472727273"/>
  117
+      </g>
  118
+     </g>
  119
+     <g id="line2d_12">
  120
+      <defs>
  121
+       <path d="
  122
+M0 0
  123
+L-4 0" id="m0d5b0a6425" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
  124
+      </defs>
  125
+      <g>
  126
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="322.472727273"/>
  127
+      </g>
  128
+     </g>
  129
+    </g>
  130
+    <g id="ytick_2">
  131
+     <g id="line2d_13">
  132
+      <g>
  133
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="252.654545455"/>
  134
+      </g>
  135
+     </g>
  136
+     <g id="line2d_14">
  137
+      <g>
  138
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="252.654545455"/>
  139
+      </g>
  140
+     </g>
  141
+    </g>
  142
+    <g id="ytick_3">
  143
+     <g id="line2d_15">
  144
+      <g>
  145
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="182.836363636"/>
  146
+      </g>
  147
+     </g>
  148
+     <g id="line2d_16">
  149
+      <g>
  150
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="182.836363636"/>
  151
+      </g>
  152
+     </g>
  153
+    </g>
  154
+    <g id="ytick_4">
  155
+     <g id="line2d_17">
  156
+      <g>
  157
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="113.018181818"/>
  158
+      </g>
  159
+     </g>
  160
+     <g id="line2d_18">
  161
+      <g>
  162
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="113.018181818"/>
  163
+      </g>
  164
+     </g>
  165
+    </g>
  166
+    <g id="ytick_5">
  167
+     <g id="line2d_19">
  168
+      <g>
  169
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="43.2"/>
  170
+      </g>
  171
+     </g>
  172
+     <g id="line2d_20">
  173
+      <g>
  174
+       <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="43.2"/>
  175
+      </g>
  176
+     </g>
  177
+    </g>
  178
+   </g>
  179
+   <g id="patch_3">
  180
+    <path d="
  181
+M72 43.2
  182
+L518.4 43.2" style="fill:none;stroke:#000000;"/>
  183
+   </g>
  184
+   <g id="patch_4">
  185
+    <path d="
  186
+M518.4 388.8
  187
+L518.4 43.2" style="fill:none;stroke:#000000;"/>
  188
+   </g>
  189
+   <g id="patch_5">
  190
+    <path d="
  191
+M72 388.8
  192
+L518.4 388.8" style="fill:none;stroke:#000000;"/>
  193
+   </g>
  194
+   <g id="patch_6">
  195
+    <path d="
  196
+M72 388.8
  197
+L72 43.2" style="fill:none;stroke:#000000;"/>
  198
+   </g>
  199
+  </g>
  200
+ </g>
  201
+ <defs>
  202
+  <clipPath id="p7ff5b81e1d">
  203
+   <rect height="345.6" width="446.4" x="72.0" y="43.2"/>
  204
+  </clipPath>
  205
+ </defs>
  206
+</svg>
15  lib/matplotlib/tests/test_image.py
@@ -160,6 +160,21 @@ def test_no_interpolation_origin():
160 160
     ax = fig.add_subplot(212)
161 161
     ax.imshow(np.arange(100).reshape((2, 50)), interpolation='none')
162 162
 
  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
+
163 178
 if __name__=='__main__':
164 179
     import nose
165 180
     nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 notes on commit 2e5a38a

Please sign in to comment.
Something went wrong with that request. Please try again.