Permalink
Browse files

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

the affine matrix is calculated in the display coordinate for interpolation='none'
  • Loading branch information...
2 parents ed7db9b + 67eb71d commit 2e5a38ac3aecb3e3e1fa536e5c690f497ddd0719 @mdboom mdboom committed Sep 5, 2012
View
@@ -25,7 +25,7 @@
# the image namespace:
from matplotlib._image import *
-from matplotlib.transforms import BboxBase, Bbox
+from matplotlib.transforms import BboxBase, Bbox, IdentityTransform
import matplotlib.transforms as mtransforms
@@ -270,8 +270,8 @@ def _draw_unsampled_image(self, renderer, gc):
# firs, convert the image extent to the ic
x_llc, x_trc, y_llc, y_trc = self.get_extent()
- xy = trans.transform_non_affine(np.array([(x_llc, y_llc),
- (x_trc, y_trc)]))
+ xy = trans.transform(np.array([(x_llc, y_llc),
+ (x_trc, y_trc)]))
_xx1, _yy1 = xy[0]
_xx2, _yy2 = xy[1]
@@ -283,15 +283,16 @@ def _draw_unsampled_image(self, renderer, gc):
if self._image_skew_coordinate:
# skew the image when required.
x_lrc, y_lrc = self._image_skew_coordinate
- xy2 = trans.transform_non_affine(np.array([(x_lrc, y_lrc)]))
+ xy2 = trans.transform(np.array([(x_lrc, y_lrc)]))
_xx3, _yy3 = xy2[0]
tr_rotate_skew = self._get_rotate_and_skew_transform(_xx1, _yy1,
_xx2, _yy2,
_xx3, _yy3)
- trans_ic_to_canvas = tr_rotate_skew+trans.get_affine()
+ trans_ic_to_canvas = tr_rotate_skew
else:
- trans_ic_to_canvas = trans.get_affine()
+ trans_ic_to_canvas = IdentityTransform()
+
# Now, viewLim in the ic. It can be rotated and can be
# skewed. Make it big enough.
@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Created with matplotlib (http://matplotlib.sourceforge.net/) -->
+<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">
+ <defs>
+ <style type="text/css">
+*{stroke-linecap:square;stroke-linejoin:round;}
+ </style>
+ </defs>
+ <g id="figure_1">
+ <g id="patch_1">
+ <path d="
+M0 432
+L576 432
+L576 0
+L0 0
+z
+" style="fill:#ffffff;"/>
+ </g>
+ <g id="axes_1">
+ <g id="patch_2">
+ <path d="
+M72 388.8
+L518.4 388.8
+L518.4 43.2
+L72 43.2
+z
+" style="fill:#ffffff;"/>
+ </g>
+ <g clip-path="url(#p7ff5b81e1d)">
+ <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,
+iVBORw0KGgoAAAANSUhEUgAAAGMAAABjCAYAAACPO76VAAAABHNCSVQICAgIfAhkiAAAC1RJREFUeJzdXcGO3DgOfZ3yViXdk81iBsgAM7cF9r63+Yb9qv29/ZwADXS6a6vSc3DJJdEk9SjJ1ckQSGxTtGzzmY+UbFff/Rd4/Q+A3wH8/AB8OAB37wHsAEyYJS13uMoEXSy9Jy37/Eiyq5sAwN3/gNc//gDwLwC/Avg7gAcA7zE76YASjB2Au2z5TvSoObbm7B4wyAt9UyGvb/odmIH4N4DfAPwC4BNmEB5QAPI6AacdcL50fp7eXZazR0670jNncRZnw3OWPpdTh9eZ/rcW6QtNpp8fMEfEbwD+CeAz8PoJeHp4h6fDPY7Y4wV7nDHhjB3O2OGEXbENXJ2VHzR3gnSI5SDP6cwFMcfokS2BnT4cMFPTLwA+A8+fgS8Pn/CIj3jCBxxxwAv2OOKAM3YrYAAs4OQnK5fJrrywt4ucKLD1/vpBmu7eY6ajT3NEfHn4hC/4Bx7xEY/4iCP2eML9AsIRezU68sioAWFFj3dRLZFU7t/m/K0iQet3wg5zsj7M1JRASIC8YI+vFzBSlNQoS4IjDy6p7arvj5St8s/ISLLOccKEOUk/AE+HezzhwwLIE+7xiJ9wxAFPmPPHCb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b6B9jkq2eVHh9cNUVJz9nzq8sOaKN6MoAAAAAElFTkSuQmCC" y="-388.8"/>
+ </g>
+ <g id="matplotlib.axis_1">
+ <g id="xtick_1">
+ <g id="line2d_1">
+ <defs>
+ <path d="
+M0 0
+L0 -4" id="mcb557df647" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="146.014526367" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_2">
+ <defs>
+ <path d="
+M0 0
+L0 4" id="mdad270ee8e" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="146.014526367" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_2">
+ <g id="line2d_3">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="223.112976074" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_4">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="223.112976074" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_3">
+ <g id="line2d_5">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="300.211425781" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_6">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="300.211425781" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_4">
+ <g id="line2d_7">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="377.309875488" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_8">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="377.309875488" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_5">
+ <g id="line2d_9">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="454.408325195" xlink:href="#mcb557df647" y="388.8"/>
+ </g>
+ </g>
+ <g id="line2d_10">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="454.408325195" xlink:href="#mdad270ee8e" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ </g>
+ <g id="matplotlib.axis_2">
+ <g id="ytick_1">
+ <g id="line2d_11">
+ <defs>
+ <path d="
+M0 0
+L4 0" id="mc8fcea1516" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="322.472727273"/>
+ </g>
+ </g>
+ <g id="line2d_12">
+ <defs>
+ <path d="
+M0 0
+L-4 0" id="m0d5b0a6425" style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="322.472727273"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_2">
+ <g id="line2d_13">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="252.654545455"/>
+ </g>
+ </g>
+ <g id="line2d_14">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="252.654545455"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_3">
+ <g id="line2d_15">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="182.836363636"/>
+ </g>
+ </g>
+ <g id="line2d_16">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="182.836363636"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_4">
+ <g id="line2d_17">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="113.018181818"/>
+ </g>
+ </g>
+ <g id="line2d_18">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="113.018181818"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_5">
+ <g id="line2d_19">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="72.0" xlink:href="#mc8fcea1516" y="43.2"/>
+ </g>
+ </g>
+ <g id="line2d_20">
+ <g>
+ <use style="stroke:#000000;stroke-linecap:butt;stroke-width:0.5;" x="518.4" xlink:href="#m0d5b0a6425" y="43.2"/>
+ </g>
+ </g>
+ </g>
+ </g>
+ <g id="patch_3">
+ <path d="
+M72 43.2
+L518.4 43.2" style="fill:none;stroke:#000000;"/>
+ </g>
+ <g id="patch_4">
+ <path d="
+M518.4 388.8
+L518.4 43.2" style="fill:none;stroke:#000000;"/>
+ </g>
+ <g id="patch_5">
+ <path d="
+M72 388.8
+L518.4 388.8" style="fill:none;stroke:#000000;"/>
+ </g>
+ <g id="patch_6">
+ <path d="
+M72 388.8
+L72 43.2" style="fill:none;stroke:#000000;"/>
+ </g>
+ </g>
+ </g>
+ <defs>
+ <clipPath id="p7ff5b81e1d">
+ <rect height="345.6" width="446.4" x="72.0" y="43.2"/>
+ </clipPath>
+ </defs>
+</svg>
@@ -160,6 +160,21 @@ def test_no_interpolation_origin():
ax = fig.add_subplot(212)
ax.imshow(np.arange(100).reshape((2, 50)), interpolation='none')
+@image_comparison(baseline_images=['image_shift'], remove_text=True,
+ extensions=['pdf', 'svg'])
+def test_image_shift():
+ from matplotlib.colors import LogNorm
+
+ imgData = [[1.0/(x) + 1.0/(y) for x in range(1,100)] for y in range(1,100)]
+ tMin=734717.945208
+ tMax=734717.946366
+
+ fig = plt.figure()
+ ax = fig.add_subplot(111)
+ ax.imshow(imgData, norm=LogNorm(), interpolation='none',
+ extent=(tMin, tMax, 1, 100))
+ ax.set_aspect('auto')
+
if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 comments on commit 2e5a38a

Please sign in to comment.