Python matplotlib.transforms.Transform() Examples
The following are 30
code examples of matplotlib.transforms.Transform().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.transforms
, or try the search function
.
Example #1
Source File: text.py From Computable with MIT License | 6 votes |
def __call__(self, renderer): if isinstance(self._artist, Artist): bbox = self._artist.get_window_extent(renderer) l, b, w, h = bbox.bounds xf, yf = self._ref_coord x, y = l + w * xf, b + h * yf elif isinstance(self._artist, BboxBase): l, b, w, h = self._artist.bounds xf, yf = self._ref_coord x, y = l + w * xf, b + h * yf elif isinstance(self._artist, Transform): x, y = self._artist.transform_point(self._ref_coord) else: raise RuntimeError("unknown type") sc = self._get_scale(renderer) tr = Affine2D().scale(sc, sc).translate(x, y) return tr
Example #2
Source File: grid_finder.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def update_transform(self, aux_trans): if isinstance(aux_trans, Transform): def transform_xy(x, y): ll1 = np.column_stack([x, y]) ll2 = aux_trans.transform(ll1) lon, lat = ll2[:,0], ll2[:,1] return lon, lat def inv_transform_xy(x, y): ll1 = np.column_stack([x, y]) ll2 = aux_trans.inverted().transform(ll1) lon, lat = ll2[:,0], ll2[:,1] return lon, lat else: transform_xy, inv_transform_xy = aux_trans self.transform_xy = transform_xy self.inv_transform_xy = inv_transform_xy
Example #3
Source File: text.py From ImageFusion with MIT License | 6 votes |
def set_clip_path(self, path, transform=None): """ Set the artist's clip path, which may be: * a :class:`~matplotlib.patches.Patch` (or subclass) instance * a :class:`~matplotlib.path.Path` instance, in which case an optional :class:`~matplotlib.transforms.Transform` instance may be provided, which will be applied to the path before using it for clipping. * *None*, to remove the clipping path For efficiency, if the path happens to be an axis-aligned rectangle, this method will set the clipping box to the corresponding rectangle and set the clipping path to *None*. ACCEPTS: [ (:class:`~matplotlib.path.Path`, :class:`~matplotlib.transforms.Transform`) | :class:`~matplotlib.patches.Patch` | None ] """ super(Text, self).set_clip_path(path, transform) self._update_clip_properties()
Example #4
Source File: text.py From ImageFusion with MIT License | 6 votes |
def __call__(self, renderer): if isinstance(self._artist, Artist): bbox = self._artist.get_window_extent(renderer) l, b, w, h = bbox.bounds xf, yf = self._ref_coord x, y = l + w * xf, b + h * yf elif isinstance(self._artist, BboxBase): l, b, w, h = self._artist.bounds xf, yf = self._ref_coord x, y = l + w * xf, b + h * yf elif isinstance(self._artist, Transform): x, y = self._artist.transform_point(self._ref_coord) else: raise RuntimeError("unknown type") sc = self._get_scale(renderer) tr = Affine2D().scale(sc, sc).translate(x, y) return tr
Example #5
Source File: grid_finder.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def update_transform(self, aux_trans): if isinstance(aux_trans, Transform): def transform_xy(x, y): ll1 = np.column_stack([x, y]) ll2 = aux_trans.transform(ll1) lon, lat = ll2[:,0], ll2[:,1] return lon, lat def inv_transform_xy(x, y): ll1 = np.column_stack([x, y]) ll2 = aux_trans.inverted().transform(ll1) lon, lat = ll2[:,0], ll2[:,1] return lon, lat else: transform_xy, inv_transform_xy = aux_trans self.transform_xy = transform_xy self.inv_transform_xy = inv_transform_xy
Example #6
Source File: text.py From neural-network-animation with MIT License | 6 votes |
def __call__(self, renderer): if isinstance(self._artist, Artist): bbox = self._artist.get_window_extent(renderer) l, b, w, h = bbox.bounds xf, yf = self._ref_coord x, y = l + w * xf, b + h * yf elif isinstance(self._artist, BboxBase): l, b, w, h = self._artist.bounds xf, yf = self._ref_coord x, y = l + w * xf, b + h * yf elif isinstance(self._artist, Transform): x, y = self._artist.transform_point(self._ref_coord) else: raise RuntimeError("unknown type") sc = self._get_scale(renderer) tr = Affine2D().scale(sc, sc).translate(x, y) return tr
Example #7
Source File: text.py From neural-network-animation with MIT License | 6 votes |
def set_clip_path(self, path, transform=None): """ Set the artist's clip path, which may be: * a :class:`~matplotlib.patches.Patch` (or subclass) instance * a :class:`~matplotlib.path.Path` instance, in which case an optional :class:`~matplotlib.transforms.Transform` instance may be provided, which will be applied to the path before using it for clipping. * *None*, to remove the clipping path For efficiency, if the path happens to be an axis-aligned rectangle, this method will set the clipping box to the corresponding rectangle and set the clipping path to *None*. ACCEPTS: [ (:class:`~matplotlib.path.Path`, :class:`~matplotlib.transforms.Transform`) | :class:`~matplotlib.patches.Patch` | None ] """ super(Text, self).set_clip_path(path, transform) self._update_clip_properties()
Example #8
Source File: grid_finder.py From CogAlg with MIT License | 6 votes |
def update_transform(self, aux_trans): if isinstance(aux_trans, Transform): def transform_xy(x, y): ll1 = np.column_stack([x, y]) ll2 = aux_trans.transform(ll1) lon, lat = ll2[:, 0], ll2[:, 1] return lon, lat def inv_transform_xy(x, y): ll1 = np.column_stack([x, y]) ll2 = aux_trans.inverted().transform(ll1) lon, lat = ll2[:, 0], ll2[:, 1] return lon, lat else: transform_xy, inv_transform_xy = aux_trans self.transform_xy = transform_xy self.inv_transform_xy = inv_transform_xy
Example #9
Source File: parse_svg.py From pylustrator with GNU General Public License v3.0 | 6 votes |
def plt_patch(node: minidom.Element, trans_parent_trans: mtransforms.Transform, style: dict, constructor: callable, ids: dict, no_draw: bool = False) -> mpatches.Patch: """ add a node to the figure by calling the provided constructor """ trans_node = parseTransformation(node.getAttribute("transform")) style = get_inline_style(node, get_css_style(node, ids["css"], style)) patch = constructor(node, trans_node + trans_parent_trans + plt.gca().transData, style, ids) if not isinstance(patch, list): patch = [patch] for p in patch: if not getattr(p, "is_marker", False): style = apply_style(style, p) p.style = style #p.set_transform(p.get_transform() + plt.gca().transData) p.trans_parent = trans_parent_trans p.trans_node = parseTransformation(node.getAttribute("transform")) if not no_draw and not styleNoDisplay(style): plt.gca().add_patch(p) if node.getAttribute("id") != "": ids[node.getAttribute("id")] = patch return patch
Example #10
Source File: transforms.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def transform(self, input_coords): """ Transform one set of coordinates to another """ if self.same_frames: return input_coords input_coords = input_coords*u.deg x_in, y_in = input_coords[:, 0], input_coords[:, 1] c_in = SkyCoord(UnitSphericalRepresentation(x_in, y_in), frame=self.input_system) # We often need to transform arrays that contain NaN values, and filtering # out the NaN values would have a performance hit, so instead we just pass # on all values and just ignore Numpy warnings with np.errstate(all='ignore'): c_out = c_in.transform_to(self.output_system) lon = c_out.spherical.lon.deg lat = c_out.spherical.lat.deg return np.concatenate((lon[:, np.newaxis], lat[:, np.newaxis]), axis=1)
Example #11
Source File: grid_finder.py From matplotlib-4-abaqus with MIT License | 6 votes |
def update_transform(self, aux_trans): if isinstance(aux_trans, Transform): def transform_xy(x, y): x, y = np.asarray(x), np.asarray(y) ll1 = np.concatenate((x[:,np.newaxis], y[:,np.newaxis]), 1) ll2 = aux_trans.transform(ll1) lon, lat = ll2[:,0], ll2[:,1] return lon, lat def inv_transform_xy(x, y): x, y = np.asarray(x), np.asarray(y) ll1 = np.concatenate((x[:,np.newaxis], y[:,np.newaxis]), 1) ll2 = aux_trans.inverted().transform(ll1) lon, lat = ll2[:,0], ll2[:,1] return lon, lat else: transform_xy, inv_transform_xy = aux_trans self.transform_xy = transform_xy self.inv_transform_xy = inv_transform_xy
Example #12
Source File: text.py From matplotlib-4-abaqus with MIT License | 6 votes |
def __call__(self, renderer): if isinstance(self._artist, Artist): bbox = self._artist.get_window_extent(renderer) l, b, w, h = bbox.bounds xf, yf = self._ref_coord x, y = l + w * xf, b + h * yf elif isinstance(self._artist, BboxBase): l, b, w, h = self._artist.bounds xf, yf = self._ref_coord x, y = l + w * xf, b + h * yf elif isinstance(self._artist, Transform): x, y = self._artist.transform_point(self._ref_coord) else: raise RuntimeError("unknown type") sc = self._get_scale(renderer) tr = Affine2D().scale(sc, sc).translate(x, y) return tr
Example #13
Source File: grid_finder.py From Computable with MIT License | 6 votes |
def update_transform(self, aux_trans): if isinstance(aux_trans, Transform): def transform_xy(x, y): x, y = np.asarray(x), np.asarray(y) ll1 = np.concatenate((x[:,np.newaxis], y[:,np.newaxis]), 1) ll2 = aux_trans.transform(ll1) lon, lat = ll2[:,0], ll2[:,1] return lon, lat def inv_transform_xy(x, y): x, y = np.asarray(x), np.asarray(y) ll1 = np.concatenate((x[:,np.newaxis], y[:,np.newaxis]), 1) ll2 = aux_trans.inverted().transform(ll1) lon, lat = ll2[:,0], ll2[:,1] return lon, lat else: transform_xy, inv_transform_xy = aux_trans self.transform_xy = transform_xy self.inv_transform_xy = inv_transform_xy
Example #14
Source File: test_transforms.py From coffeegrindsize with MIT License | 5 votes |
def __init__(self, real_trans, *args, **kwargs): self.real_trans = real_trans mtransforms.Transform.__init__(self, *args, **kwargs)
Example #15
Source File: contour.py From twitter-stock-recommendation with MIT License | 5 votes |
def get_transform(self): """ Return the :class:`~matplotlib.transforms.Transform` instance used by this ContourSet. """ if self._transform is None: self._transform = self.ax.transData elif (not isinstance(self._transform, mtransforms.Transform) and hasattr(self._transform, '_as_mpl_transform')): self._transform = self._transform._as_mpl_transform(self.ax) return self._transform
Example #16
Source File: text.py From Computable with MIT License | 5 votes |
def set_transform(self, t): """ Set the :class:`matplotlib.transforms.Transform` instance used by this artist. ACCEPTS: a :class:`matplotlib.transforms.Transform` instance """ Text.set_transform(self, t) self.dashline.set_transform(t)
Example #17
Source File: text.py From ImageFusion with MIT License | 5 votes |
def set_transform(self, t): """ Set the :class:`matplotlib.transforms.Transform` instance used by this artist. ACCEPTS: a :class:`matplotlib.transforms.Transform` instance """ Text.set_transform(self, t) self.dashline.set_transform(t)
Example #18
Source File: test_transforms.py From twitter-stock-recommendation with MIT License | 5 votes |
def __init__(self, real_trans, *args, **kwargs): self.real_trans = real_trans mtransforms.Transform.__init__(self, *args, **kwargs)
Example #19
Source File: collections.py From ImageFusion with MIT License | 5 votes |
def get_offset_transform(self): t = self._transOffset if (not isinstance(t, transforms.Transform) and hasattr(t, '_as_mpl_transform')): t = t._as_mpl_transform(self.axes) return t
Example #20
Source File: test_transforms.py From ImageFusion with MIT License | 5 votes |
def test_non_affine_caching(): class AssertingNonAffineTransform(mtrans.Transform): """ This transform raises an assertion error when called when it shouldn't be and self.raise_on_transform is True. """ input_dims = output_dims = 2 is_affine = False def __init__(self, *args, **kwargs): mtrans.Transform.__init__(self, *args, **kwargs) self.raise_on_transform = False self.underlying_transform = mtrans.Affine2D().scale(10, 10) def transform_path_non_affine(self, path): if self.raise_on_transform: assert False, ('Invalidated affine part of transform ' 'unnecessarily.') return self.underlying_transform.transform_path(path) transform_path = transform_path_non_affine def transform_non_affine(self, path): if self.raise_on_transform: assert False, ('Invalidated affine part of transform ' 'unnecessarily.') return self.underlying_transform.transform(path) transform = transform_non_affine my_trans = AssertingNonAffineTransform() ax = plt.axes() plt.plot(list(xrange(10)), transform=my_trans + ax.transData) plt.draw() # enable the transform to raise an exception if it's non-affine transform # method is triggered again. my_trans.raise_on_transform = True ax.transAxes.invalidate() plt.draw()
Example #21
Source File: polar.py From coffeegrindsize with MIT License | 5 votes |
def __init__(self, axis=None, use_rmin=True, _apply_theta_transforms=True): mtransforms.Transform.__init__(self) self._axis = axis self._use_rmin = use_rmin self._apply_theta_transforms = _apply_theta_transforms
Example #22
Source File: polar.py From coffeegrindsize with MIT License | 5 votes |
def __init__(self, axis=None, use_rmin=True, _apply_theta_transforms=True): mtransforms.Transform.__init__(self) self._axis = axis self._use_rmin = use_rmin self._apply_theta_transforms = _apply_theta_transforms
Example #23
Source File: test_transforms.py From coffeegrindsize with MIT License | 5 votes |
def test_non_affine_caching(): class AssertingNonAffineTransform(mtransforms.Transform): """ This transform raises an assertion error when called when it shouldn't be and self.raise_on_transform is True. """ input_dims = output_dims = 2 is_affine = False def __init__(self, *args, **kwargs): mtransforms.Transform.__init__(self, *args, **kwargs) self.raise_on_transform = False self.underlying_transform = mtransforms.Affine2D().scale(10, 10) def transform_path_non_affine(self, path): assert not self.raise_on_transform, \ 'Invalidated affine part of transform unnecessarily.' return self.underlying_transform.transform_path(path) transform_path = transform_path_non_affine def transform_non_affine(self, path): assert not self.raise_on_transform, \ 'Invalidated affine part of transform unnecessarily.' return self.underlying_transform.transform(path) transform = transform_non_affine my_trans = AssertingNonAffineTransform() ax = plt.axes() plt.plot(np.arange(10), transform=my_trans + ax.transData) plt.draw() # enable the transform to raise an exception if it's non-affine transform # method is triggered again. my_trans.raise_on_transform = True ax.transAxes.invalidate() plt.draw()
Example #24
Source File: transforms.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def transform(self, world): """ Transform world to pixel coordinates. You should pass in a NxM array where N is the number of points to transform, and M is the number of dimensions. This then returns the (x, y) pixel coordinates as a Nx2 array. """
Example #25
Source File: contour.py From coffeegrindsize with MIT License | 5 votes |
def get_transform(self): """ Return the :class:`~matplotlib.transforms.Transform` instance used by this ContourSet. """ if self._transform is None: self._transform = self.ax.transData elif (not isinstance(self._transform, mtransforms.Transform) and hasattr(self._transform, '_as_mpl_transform')): self._transform = self._transform._as_mpl_transform(self.ax) return self._transform
Example #26
Source File: test_transforms.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_non_affine_caching(): class AssertingNonAffineTransform(mtransforms.Transform): """ This transform raises an assertion error when called when it shouldn't be and self.raise_on_transform is True. """ input_dims = output_dims = 2 is_affine = False def __init__(self, *args, **kwargs): mtransforms.Transform.__init__(self, *args, **kwargs) self.raise_on_transform = False self.underlying_transform = mtransforms.Affine2D().scale(10, 10) def transform_path_non_affine(self, path): assert not self.raise_on_transform, \ 'Invalidated affine part of transform unnecessarily.' return self.underlying_transform.transform_path(path) transform_path = transform_path_non_affine def transform_non_affine(self, path): assert not self.raise_on_transform, \ 'Invalidated affine part of transform unnecessarily.' return self.underlying_transform.transform(path) transform = transform_non_affine my_trans = AssertingNonAffineTransform() ax = plt.axes() plt.plot(np.arange(10), transform=my_trans + ax.transData) plt.draw() # enable the transform to raise an exception if it's non-affine transform # method is triggered again. my_trans.raise_on_transform = True ax.transAxes.invalidate() plt.draw()
Example #27
Source File: polar.py From CogAlg with MIT License | 5 votes |
def __init__(self, axis=None, use_rmin=True, _apply_theta_transforms=True): mtransforms.Transform.__init__(self) self._axis = axis self._use_rmin = use_rmin self._apply_theta_transforms = _apply_theta_transforms
Example #28
Source File: polar.py From twitter-stock-recommendation with MIT License | 5 votes |
def __init__(self, axis=None, use_rmin=True, _apply_theta_transforms=True): mtransforms.Transform.__init__(self) self._axis = axis self._use_rmin = use_rmin self._apply_theta_transforms = _apply_theta_transforms
Example #29
Source File: polar.py From CogAlg with MIT License | 5 votes |
def __init__(self, axis=None, use_rmin=True, _apply_theta_transforms=True): mtransforms.Transform.__init__(self) self._axis = axis self._use_rmin = use_rmin self._apply_theta_transforms = _apply_theta_transforms
Example #30
Source File: contour.py From CogAlg with MIT License | 5 votes |
def get_transform(self): """ Return the :class:`~matplotlib.transforms.Transform` instance used by this ContourSet. """ if self._transform is None: self._transform = self.ax.transData elif (not isinstance(self._transform, mtransforms.Transform) and hasattr(self._transform, '_as_mpl_transform')): self._transform = self._transform._as_mpl_transform(self.ax) return self._transform