本文整理汇总了Python中matplotlib.patches.Ellipse.set_visible方法的典型用法代码示例。如果您正苦于以下问题:Python Ellipse.set_visible方法的具体用法?Python Ellipse.set_visible怎么用?Python Ellipse.set_visible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Ellipse
的用法示例。
在下文中一共展示了Ellipse.set_visible方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MplCircularROI
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_visible [as 别名]
class MplCircularROI(AbstractMplRoi):
"""
Matplotlib ROI for circular selections
Since circles on the screen may not be circles in the data (due, e.g., to
logarithmic scalings on the axes), the ultimate ROI that is created is a
polygonal ROI
Parameters
----------
axes : `~matplotlib.axes.Axes`
The Matplotlib axes to draw to.
"""
_roi_cls = CircularROI
def __init__(self, axes):
super(MplCircularROI, self).__init__(axes)
self.plot_opts = {'edgecolor': PATCH_COLOR,
'facecolor': PATCH_COLOR,
'alpha': 0.3}
self._xi = None
self._yi = None
self._patch = Ellipse((0., 0.), transform=IdentityTransform(),
width=0., height=0., zorder=100)
self._patch.set_visible(False)
self._axes.add_patch(self._patch)
def _sync_patch(self):
if self._roi.defined():
xy = self._roi.get_center()
r = self._roi.get_radius()
self._patch.center = xy
self._patch.width = 2. * r
self._patch.height = 2. * r
self._patch.set(**self.plot_opts)
self._patch.set_visible(True)
else:
self._patch.set_visible(False)
def start_selection(self, event):
if event.inaxes != self._axes:
return False
xy = data_to_pixel(self._axes, [event.xdata], [event.ydata])
xi = xy[0, 0]
yi = xy[0, 1]
if event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
elif not self._roi.contains(xi, yi):
return False
self._store_previous_roi()
self._store_background()
if event.key == SCRUBBING_KEY:
self._scrubbing = True
(xc, yc) = self._roi.get_center()
self._dx = xc - xi
self._dy = yc - yi
else:
self.reset()
self._roi.set_center(xi, yi)
self._roi.set_radius(0.)
self._xi = xi
self._yi = yi
self._mid_selection = True
self._sync_patch()
self._draw()
def update_selection(self, event):
if not self._mid_selection or event.inaxes != self._axes:
return False
xy = data_to_pixel(self._axes, [event.xdata], [event.ydata])
xi = xy[0, 0]
yi = xy[0, 1]
if event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
if self._scrubbing:
self._roi.set_center(xi + self._dx, yi + self._dy)
else:
dx = xy[0, 0] - self._xi
dy = xy[0, 1] - self._yi
self._roi.set_radius(np.hypot(dx, dy))
self._sync_patch()
#.........这里部分代码省略.........
示例2: MplCircularROI
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_visible [as 别名]
class MplCircularROI(AbstractMplRoi):
"""
Class to display / edit circular ROIs using matplotlib
Since circles on the screen may not be circles in the data
(due, e.g., to logarithmic scalings on the axes), the
ultimate ROI that is created is a polygonal ROI
:param plot_opts:
A dictionary of plot keywords that are passed to
the patch representing the ROI. These control
the visual properties of the ROI
"""
def __init__(self, axes):
"""
:param axes: A matplotlib Axes object to attach the graphical ROI to
"""
AbstractMplRoi.__init__(self, axes)
self.plot_opts = {'edgecolor': PATCH_COLOR, 'facecolor': PATCH_COLOR,
'alpha': 0.3}
self._xi = None
self._yi = None
self._setup_patch()
def _setup_patch(self):
self._patch = Ellipse((0., 0.), transform=IdentityTransform(),
width=0., height=0.,)
self._patch.set_zorder(100)
self._patch.set(**self.plot_opts)
self._axes.add_patch(self._patch)
self._patch.set_visible(False)
self._sync_patch()
def _roi_factory(self):
return CircularROI()
def _sync_patch(self):
# Update geometry
if not self._roi.defined():
self._patch.set_visible(False)
else:
xy = self._roi.get_center()
r = self._roi.get_radius()
self._patch.center = xy
self._patch.width = 2. * r
self._patch.height = 2. * r
self._patch.set_visible(True)
# Update appearance
self._patch.set(**self.plot_opts)
# Refresh
self._axes.figure.canvas.draw()
def start_selection(self, event):
if event.inaxes != self._axes:
return False
xy = data_to_pixel(self._axes, [event.xdata], [event.ydata])
xi = xy[0, 0]
yi = xy[0, 1]
if event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
elif not self._roi.contains(xi, yi):
return False
self._roi_store()
if event.key == SCRUBBING_KEY:
self._scrubbing = True
(xc, yc) = self._roi.get_center()
self._dx = xc - xi
self._dy = yc - yi
else:
self.reset()
self._roi.set_center(xi, yi)
self._roi.set_radius(0.)
self._xi = xi
self._yi = yi
self._mid_selection = True
self._sync_patch()
def update_selection(self, event):
if not self._mid_selection or event.inaxes != self._axes:
return False
xy = data_to_pixel(self._axes, [event.xdata], [event.ydata])
xi = xy[0, 0]
yi = xy[0, 1]
#.........这里部分代码省略.........
示例3: PointTool
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_visible [as 别名]
class PointTool(ROIToolBase):
"""Widget for painting on top of a plot.
Parameters
----------
ax : :class:`matplotlib.axes.Axes`
Matplotlib axes where tool is displayed.
overlay_shape : shape tuple
2D shape tuple used to initialize overlay image.
alpha : float (between [0, 1])
Opacity of overlay
on_move : function
Function called whenever a control handle is moved.
This function must accept the end points of line as the only argument.
on_release : function
Function called whenever the control handle is released.
on_enter : function
Function called whenever the "enter" key is pressed.
rect_props : dict
Properties for :class:`matplotlib.patches.Rectangle`. This class
redefines defaults in :class:`matplotlib.widgets.RectangleSelector`.
Attributes
----------
overlay : array
Overlay of painted labels displayed on top of image.
label : int
Current paint color.
"""
def __init__(self, ax, radius=2, on_move=None,
on_release=None, on_enter=None, useblit=True,
shape_props=None):
super(PointTool, self).__init__(ax, on_move=on_move, on_enter=on_enter,
on_release=on_release, useblit=useblit)
props = dict(edgecolor='b', facecolor='w', alpha=0.5, linewidth=2, animated=True)
props.update(shape_props if shape_props is not None else {})
self._point = Ellipse((0, 0), 0, 0, **props)
self._point.set_visible(False)
self.ax.add_patch(self._point)
# `radius` can only be set after initializing `_point`
self._radius = radius
self._artists = [self._point]
self._position = 0, 0
self.shape = 'point'
@property
def radii(self):
dia = 2 * self._radius
# translate to pixels
# calculate asymmetry of x and y axes:
x0, y0 = self.ax.transAxes.transform((0, 0)) # lower left in pixels
x1, y1 = self.ax.transAxes.transform((1, 1)) # upper right in pixels
dx = x1 - x0
dy = abs(y1 - y0)
maxd = max(dx, dy)
x1, x2 = self.ax.get_xlim()
y1, y2 = self.ax.get_ylim()
y2 = max(y1, y2)
width = maxd / dx * dia / 100. * x2
height = maxd / dy * dia / 100. * y2
return width, height
def _on_key_press(self, event):
if not self.active:
return
if event.key == 'enter':
self.callback_on_enter(self.geometry)
self.redraw()
def on_mouse_press(self, event):
if event.button != 1 or not self.ax.in_axes(event):
return
if not self.active:
return
self.update_point(event.xdata, event.ydata)
self.start(event)
def on_mouse_release(self, event):
if event.button != 1 or not self.active:
return
self.finalize()
def update_point(self, x, y):
self._point.width, self._point.height = self.radii
self._point.set_visible(True)
self._point.center = (x, y)
self._position = (x, y)
self.redraw()
@property
def geometry(self):
return self._position
@geometry.setter
def geometry(self, pt):
x, y = pt
self.update_point(x, y)
@property
#.........这里部分代码省略.........