本文整理汇总了Python中transforms.TransformedPath.get_transformed_path_and_affine方法的典型用法代码示例。如果您正苦于以下问题:Python TransformedPath.get_transformed_path_and_affine方法的具体用法?Python TransformedPath.get_transformed_path_and_affine怎么用?Python TransformedPath.get_transformed_path_and_affine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transforms.TransformedPath
的用法示例。
在下文中一共展示了TransformedPath.get_transformed_path_and_affine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Line2D
# 需要导入模块: from transforms import TransformedPath [as 别名]
# 或者: from transforms.TransformedPath import get_transformed_path_and_affine [as 别名]
#.........这里部分代码省略.........
self._invalidx = True
self._invalidy = True
self.set_data(xdata, ydata)
def contains(self, mouseevent):
"""
Test whether the mouse event occurred on the line. The pick
radius determines the precision of the location test (usually
within five points of the value). Use
:meth:`~matplotlib.lines.Line2D.get_pickradius` or
:meth:`~matplotlib.lines.Line2D.set_pickradius` to view or
modify it.
Returns *True* if any values are within the radius along with
``{'ind': pointlist}``, where *pointlist* is the set of points
within the radius.
TODO: sort returned indices by distance
"""
if callable(self._contains):
return self._contains(self,mouseevent)
if not is_numlike(self.pickradius):
raise ValueError("pick radius should be a distance")
# Make sure we have data to plot
if self._invalidy or self._invalidx:
self.recache()
if len(self._xy)==0: return False,{}
# Convert points to pixels
if self._transformed_path is None:
self._transform_path()
path, affine = self._transformed_path.get_transformed_path_and_affine()
path = affine.transform_path(path)
xy = path.vertices
xt = xy[:, 0]
yt = xy[:, 1]
# Convert pick radius from points to pixels
if self.figure == None:
warning.warn('no figure set when check if mouse is on line')
pixels = self.pickradius
else:
pixels = self.figure.dpi/72. * self.pickradius
# the math involved in checking for containment (here and inside of segment_hits) assumes
# that it is OK to overflow. In case the application has set the error flags such that
# an exception is raised on overflow, we temporarily set the appropriate error flags here
# and set them back when we are finished.
olderrflags = np.seterr(all='ignore')
try:
# Check for collision
if self._linestyle in ['None',None]:
# If no line, return the nearby point(s)
d = (xt-mouseevent.x)**2 + (yt-mouseevent.y)**2
ind, = np.nonzero(np.less_equal(d, pixels**2))
else:
# If line, return the nearby segment(s)
ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels)
finally:
np.seterr(**olderrflags)
ind += self.ind_offset
# Debugging message
示例2: Artist
# 需要导入模块: from transforms import TransformedPath [as 别名]
# 或者: from transforms.TransformedPath import get_transformed_path_and_affine [as 别名]
#.........这里部分代码省略.........
"""
Return the alpha value used for blending - not supported on all
backends
"""
return self._alpha
def get_visible(self):
"Return the artist's visiblity"
return self._visible
def get_animated(self):
"Return the artist's animated state"
return self._animated
def get_clip_on(self):
'Return whether artist uses clipping'
return self._clipon
def get_clip_box(self):
'Return artist clipbox'
return self.clipbox
def get_clip_path(self):
'Return artist clip path'
return self._clippath
def get_transformed_clip_path_and_affine(self):
'''
Return the clip path with the non-affine part of its
transformation applied, and the remaining affine part of its
transformation.
'''
if self._clippath is not None:
return self._clippath.get_transformed_path_and_affine()
return None, None
def set_clip_on(self, b):
"""
Set whether artist uses clipping.
ACCEPTS: [True | False]
"""
self._clipon = b
self.pchanged()
def _set_gc_clip(self, gc):
'Set the clip properly for the gc'
if self._clipon:
if self.clipbox is not None:
gc.set_clip_rectangle(self.clipbox)
gc.set_clip_path(self._clippath)
else:
gc.set_clip_rectangle(None)
gc.set_clip_path(None)
def get_rasterized(self):
"return True if the artist is to be rasterized"
return self._rasterized
def set_rasterized(self, rasterized):
"""
Force rasterized (bitmap) drawing in vector backend output.
Defaults to None, which implies the backend's default behavior
ACCEPTS: [True | False | None]
示例3: Line2D
# 需要导入模块: from transforms import TransformedPath [as 别名]
# 或者: from transforms.TransformedPath import get_transformed_path_and_affine [as 别名]
#.........这里部分代码省略.........
self._xorig = np.asarray([])
self._yorig = np.asarray([])
self._invalid = True
self.set_data(xdata, ydata)
def contains(self, mouseevent):
"""
Test whether the mouse event occurred on the line. The pick
radius determines the precision of the location test (usually
within five points of the value). Use
:meth:`~matplotlib.lines.Line2D.get_pickradius`/:meth:`~matplotlib.lines.Line2D.set_pickradius`
to view or modify it.
Returns *True* if any values are within the radius along with
``{'ind': pointlist}``, where *pointlist* is the set of points
within the radius.
TODO: sort returned indices by distance
"""
if callable(self._contains):
return self._contains(self, mouseevent)
if not is_numlike(self.pickradius):
raise ValueError, "pick radius should be a distance"
# Make sure we have data to plot
if self._invalid:
self.recache()
if len(self._xy) == 0:
return False, {}
# Convert points to pixels
path, affine = self._transformed_path.get_transformed_path_and_affine()
path = affine.transform_path(path)
xy = path.vertices
xt = xy[:, 0]
yt = xy[:, 1]
# Convert pick radius from points to pixels
if self.figure == None:
warning.warn("no figure set when check if mouse is on line")
pixels = self.pickradius
else:
pixels = self.figure.dpi / 72.0 * self.pickradius
# Check for collision
if self._linestyle in ["None", None]:
# If no line, return the nearby point(s)
d = (xt - mouseevent.x) ** 2 + (yt - mouseevent.y) ** 2
ind, = np.nonzero(np.less_equal(d, pixels ** 2))
else:
# If line, return the nearby segment(s)
ind = segment_hits(mouseevent.x, mouseevent.y, xt, yt, pixels)
# Debugging message
if False and self._label != u"":
print "Checking line", self._label, "at", mouseevent.x, mouseevent.y
print "xt", xt
print "yt", yt
# print 'dx,dy', (xt-mouseevent.x)**2., (yt-mouseevent.y)**2.
print "ind", ind
# Return the point(s) within radius
return len(ind) > 0, dict(ind=ind)