本文整理汇总了Python中matplotlib.patches.Rectangle.set_animated方法的典型用法代码示例。如果您正苦于以下问题:Python Rectangle.set_animated方法的具体用法?Python Rectangle.set_animated怎么用?Python Rectangle.set_animated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Rectangle
的用法示例。
在下文中一共展示了Rectangle.set_animated方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addItem
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_animated [as 别名]
def addItem(self, x, y, legend, shape, color, fill, overlay, z):
xView = numpy.array(x, copy=False)
yView = numpy.array(y, copy=False)
if shape == "line":
item = self.ax.plot(x, y, label=legend, color=color,
linestyle='-', marker=None)[0]
elif shape == "hline":
if hasattr(y, "__len__"):
y = y[-1]
item = self.ax.axhline(y, label=legend, color=color)
elif shape == "vline":
if hasattr(x, "__len__"):
x = x[-1]
item = self.ax.axvline(x, label=legend, color=color)
elif shape == 'rectangle':
xMin = numpy.nanmin(xView)
xMax = numpy.nanmax(xView)
yMin = numpy.nanmin(yView)
yMax = numpy.nanmax(yView)
w = xMax - xMin
h = yMax - yMin
item = Rectangle(xy=(xMin, yMin),
width=w,
height=h,
fill=False,
color=color)
if fill:
item.set_hatch('.')
self.ax.add_patch(item)
elif shape in ('polygon', 'polylines'):
xView = xView.reshape(1, -1)
yView = yView.reshape(1, -1)
item = Polygon(numpy.vstack((xView, yView)).T,
closed=(shape == 'polygon'),
fill=False,
label=legend,
color=color)
if fill and shape == 'polygon':
item.set_hatch('/')
self.ax.add_patch(item)
else:
raise NotImplementedError("Unsupported item shape %s" % shape)
item.set_zorder(z)
if overlay:
item.set_animated(True)
self._overlays.add(item)
return item
示例2: addItem
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_animated [as 别名]
def addItem(self, x, y, legend, shape, color, fill, overlay, z,
linestyle, linewidth, linebgcolor):
if (linebgcolor is not None and
shape not in ('rectangle', 'polygon', 'polylines')):
_logger.warning(
'linebgcolor not implemented for %s with matplotlib backend',
shape)
xView = numpy.array(x, copy=False)
yView = numpy.array(y, copy=False)
linestyle = normalize_linestyle(linestyle)
if shape == "line":
item = self.ax.plot(x, y, label=legend, color=color,
linestyle=linestyle, linewidth=linewidth,
marker=None)[0]
elif shape == "hline":
if hasattr(y, "__len__"):
y = y[-1]
item = self.ax.axhline(y, label=legend, color=color,
linestyle=linestyle, linewidth=linewidth)
elif shape == "vline":
if hasattr(x, "__len__"):
x = x[-1]
item = self.ax.axvline(x, label=legend, color=color,
linestyle=linestyle, linewidth=linewidth)
elif shape == 'rectangle':
xMin = numpy.nanmin(xView)
xMax = numpy.nanmax(xView)
yMin = numpy.nanmin(yView)
yMax = numpy.nanmax(yView)
w = xMax - xMin
h = yMax - yMin
item = Rectangle(xy=(xMin, yMin),
width=w,
height=h,
fill=False,
color=color,
linestyle=linestyle,
linewidth=linewidth)
if fill:
item.set_hatch('.')
if linestyle != "solid" and linebgcolor is not None:
item = _DoubleColoredLinePatch(item)
item.linebgcolor = linebgcolor
self.ax.add_patch(item)
elif shape in ('polygon', 'polylines'):
points = numpy.array((xView, yView)).T
if shape == 'polygon':
closed = True
else: # shape == 'polylines'
closed = numpy.all(numpy.equal(points[0], points[-1]))
item = Polygon(points,
closed=closed,
fill=False,
label=legend,
color=color,
linestyle=linestyle,
linewidth=linewidth)
if fill and shape == 'polygon':
item.set_hatch('/')
if linestyle != "solid" and linebgcolor is not None:
item = _DoubleColoredLinePatch(item)
item.linebgcolor = linebgcolor
self.ax.add_patch(item)
else:
raise NotImplementedError("Unsupported item shape %s" % shape)
item.set_zorder(z)
if overlay:
item.set_animated(True)
self._overlays.add(item)
return item
示例3: WindowSelectionRectangle
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_animated [as 别名]
class WindowSelectionRectangle(object):
def __init__(self, event, axis, on_window_selection_callback):
self.axis = axis
if event.inaxes != self.axis:
return
# Store the axes it has been initialized in.
self.axes = event.inaxes
ymin, ymax = self.axes.get_ylim()
self.min_x = event.xdata
self.intial_selection_active = True
self.rect = Rectangle((event.xdata, ymin), 0, ymax - ymin, color="0.3",
alpha=0.5, edgecolor="0.5")
self.axes.add_patch(self.rect)
# Get the canvas.
self.canvas = self.rect.figure.canvas
# Use blittig for fast animations.
self.rect.set_animated(True)
self.background = self.canvas.copy_from_bbox(self.rect.axes.bbox)
self._connect()
self.on_window_selection_callback = on_window_selection_callback
#def __del__(self):
#"""
#Disconnect the events upon deallocating.
#"""
#self.canvas.mpl_disconnect(self.conn_button_press)
#self.canvas.mpl_disconnect(self.conn_button_release)
#self.canvas.mpl_disconnect(self.conn_mouse_motion)
def _connect(self):
"""
Connect to the necessary events.
"""
self.conn_button_press = self.rect.figure.canvas.mpl_connect(
'button_press_event', self.on_button_press)
self.conn_button_release = self.rect.figure.canvas.mpl_connect(
'button_release_event', self.on_button_release)
self.conn_mouse_motion = self.rect.figure.canvas.mpl_connect(
'motion_notify_event', self.on_mouse_motion)
def on_button_press(self, event):
pass
def on_button_release(self, event):
if event.inaxes != self.axis:
return
if event.button != 1:
return
# turn off the rect animation property and reset the background
self.rect.set_animated(False)
self.background = None
self.intial_selection_active = False
self.canvas.draw()
x = self.rect.get_x()
width = self.rect.get_width()
if width < 0:
x = x + width
width = abs(width)
self.on_window_selection_callback(x, width, self.axis)
def on_mouse_motion(self, event):
if event.button != 1 or \
self.intial_selection_active is not True:
return
if event.xdata is not None:
self.rect.set_width(event.xdata - self.min_x)
# restore the background region
self.canvas.restore_region(self.background)
# redraw just the current rectangle
self.axes.draw_artist(self.rect)
# blit just the redrawn area
self.canvas.blit(self.axes.bbox)
示例4: __init__
# 需要导入模块: from matplotlib.patches import Rectangle [as 别名]
# 或者: from matplotlib.patches.Rectangle import set_animated [as 别名]
class Selector:
def __init__(self, filenames):
self.filenames = filenames
try:
self.filename = next(self.filenames)
except:
print("No more images to be labelled")
self.image = Image.open(RAW_FOLDER + self.filename)
print("Labeling", self.filename)
self.counter = 0
self.fig, self.ax = plt.subplots(1, 1, figsize=(14, 8))
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
self.x = [0, 0]
self.y = [0, 0]
self.samples = {}
self.on = False
self.hasNext = True
self.options = None
self.ax.imshow(self.image)
self.rect = Rectangle((0,0), 0, 0, fill=None, linewidth=2, color="r")
self.ax.add_patch(self.rect)
self.ax.figure.canvas.mpl_connect('button_press_event', self.press)
self.ax.figure.canvas.mpl_connect('motion_notify_event', self.move)
self.ax.figure.canvas.mpl_connect('button_release_event', self.release)
self.fig.canvas.mpl_connect('key_press_event', self.terminate)
self.fig.canvas.mpl_connect('close_event', self.close)
plt.show()
def terminate(self, event):
"""
x: close and save
c: close without saving
"""
if event.key:
if event.key == "x":
self.hasNext = False
plt.close()
self.close()
elif event.key == "c":
plt.close()
def press(self, event):
"""
Mouse click event
"""
if (-1 < event.xdata < self.image.size[0]) and (-1 < event.ydata < self.image.size[1]):
self.on = True
self.x[0], self.y[0] = event.xdata, event.ydata
self.rect.set_visible(True)
self.rect.set_animated(True)
self.fig.canvas.draw()
self.background = self.fig.canvas.copy_from_bbox(self.rect.axes.bbox)
self.ax.draw_artist(self.rect)
self.fig.canvas.blit(self.ax.bbox)
def move(self, event):
"""
Mousemove event
"""
if self.on:
if event.xdata is not None and event.ydata is not None:
self.x[1], self.y[1] = event.xdata, event.ydata
self.rect.set_width(abs(self.x[1] - self.x[0]))
self.rect.set_height(abs(self.y[1] - self.y[0]))
self.rect.set_xy((min(self.x), min(self.y)))
self.fig.canvas.restore_region(self.background)
self.ax.draw_artist(self.rect)
self.fig.canvas.blit(self.ax.bbox)
def release(self, event):
"""
Mouse release event
"""
if self.on:
self.on = False
self.background = None
if self.options is not None:
self.options.window.destroy()
self.options = Select()
self.options.window.mainloop()
self.rect.set_width(0)
self.rect.set_height(0)
self.rect.set_visible(False)
self.fig.canvas.draw()
#.........这里部分代码省略.........