Example #1
0
def test_imshow_clip():
    # As originally reported by Gellule Xg <*****@*****.**>

    #Create a NxN image
    N = 100
    (x, y) = np.indices((N, N))
    x -= N / 2
    y -= N / 2
    r = np.sqrt(x**2 + y**2 - x * y)

    #Create a contour plot at N/4 and extract both the clip path and transform
    fig = plt.figure()
    ax = fig.add_subplot(111)

    c = ax.contour(r, [N / 4])
    x = c.collections[0]
    clipPath = x.get_paths()[0]
    clipTransform = x.get_transform()

    from matplotlib.transforms import TransformedPath
    clip_path = TransformedPath(clipPath, clipTransform)

    #Plot the image clipped by the contour
    ax.imshow(r, clip_path=clip_path)
    fig.savefig('imshow_clip')
Example #2
0
def _get_display_coordination(artist):
    """
    Ref: matplotlib.lines.Line2D.contains
    It is intended to transform the coordination system
    to ``display``.
    Is it really necessary?
    """
    transformed_path = TransformedPath(artist.get_path(),
                                       artist.get_transform())
    path, affine = transformed_path.get_transformed_path_and_affine()
    path = affine.transform_path(path)
    xy = path.vertices
    return xy
Example #3
0
def test_transformed_path():
    points = [(0, 0), (1, 0), (1, 1), (0, 1)]
    codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY]
    path = Path(points, codes)

    trans = mtrans.Affine2D()
    trans_path = TransformedPath(path, trans)
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       points)

    # Changing the transform should change the result.
    r2 = 1 / np.sqrt(2)
    trans.rotate(np.pi / 4)
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       [(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])

    # Changing the path does not change the result (it's cached).
    path.points = [(0, 0)] * 4
    assert np.allclose(trans_path.get_fully_transformed_path().vertices,
                       [(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])
Example #4
0
    def recache(self):

        self._transformed_path = TransformedPath(self._path,
                                                 self.get_transform())

        self._invalid = False
Example #5
0
 def _get_transformed_clip_path(self):
     x, y, width, height = self.state.clipping_path
     rect = ((x, y), (x + width, y), (x + width, y + height), (x,
                                                               y + height))
     transform = Affine2D.from_values(*affine.affine_params(self.get_ctm()))
     return TransformedPath(Path(rect), transform)
Example #6
0
 def _transform_path(self):
     _path = Path(self._xydata)
     self._transformed_path = TransformedPath(_path, self.get_transform())