本文整理汇总了Python中matplotlib.widgets.RectangleSelector.disconnect_events方法的典型用法代码示例。如果您正苦于以下问题:Python RectangleSelector.disconnect_events方法的具体用法?Python RectangleSelector.disconnect_events怎么用?Python RectangleSelector.disconnect_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.widgets.RectangleSelector
的用法示例。
在下文中一共展示了RectangleSelector.disconnect_events方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SelectFromCollection
# 需要导入模块: from matplotlib.widgets import RectangleSelector [as 别名]
# 或者: from matplotlib.widgets.RectangleSelector import disconnect_events [as 别名]
class SelectFromCollection(object):
"""Select indices from a matplotlib collection using `LassoSelector`.
Selected indices are saved in the `ind` attribute. This tool highlights
selected points by fading them out (i.e., reducing their alpha values).
If your collection has alpha < 1, this tool will permanently alter them.
Note that this tool selects collection objects based on their *origins*
(i.e., `offsets`).
Parameters
----------
ax : :class:`~matplotlib.axes.Axes`
Axes to interact with.
collection : :class:`matplotlib.collections.Collection` subclass
Collection you want to select from.
alpha_other : 0 <= float <= 1
To highlight a selection, this tool sets all selected points to an
alpha value of 1 and non-selected points to `alpha_other`.
"""
def __init__(self, ax, collection, alpha_other=0.3):
self.canvas = ax.figure.canvas
self.collection = collection
self.alpha_other = alpha_other
self.xys = collection.get_offsets()
self.Npts = len(self.xys)
# Ensure that we have separate colors for each object
self.fc = collection.get_facecolors()
if len(self.fc) == 0:
raise ValueError('Collection must have a facecolor')
elif len(self.fc) == 1:
self.fc = np.tile(self.fc, self.Npts).reshape(self.Npts, -1)
self.lasso = RectangleSelector(ax, onselect=self.onselect) # Sprememba glede na originalno kodo
self.ind = []
def onselect(self, verts):
path = Path(verts)
self.ind = np.nonzero([path.contains_point(xy) for xy in self.xys])[0]
self.fc[:, -1] = self.alpha_other
self.fc[self.ind, -1] = 1
self.collection.set_facecolors(self.fc)
self.canvas.draw_idle()
def disconnect(self):
self.lasso.disconnect_events()
self.fc[:, -1] = 1
self.collection.set_facecolors(self.fc)
self.canvas.draw_idle()
示例2: WidgetFigure
# 需要导入模块: from matplotlib.widgets import RectangleSelector [as 别名]
# 或者: from matplotlib.widgets.RectangleSelector import disconnect_events [as 别名]
#.........这里部分代码省略.........
:param x1: float
:param x2: float
:param y1: float
:param y2: float
:return: normalized normal vector with one component = 1 and one component < 1
"""
delta_x = float(x1-x2)
delta_y = float(y1-y2)
if delta_y != 0:
n1 = 1.0
n2 = -delta_x/delta_y
if abs(n2) > 1.0:
n1 = n1/n2
n2 = 1.0
else:
n1 = 0.0
n2 = 1.0
return n1, n2
@on_trait_change('line_width')
def _update_line_width(self):
if self.line_selector is None:
line = 'line 0'
else:
line = self.get_widget_line(self.line_selector)
self.get_widget_line(line).drl.line.set_linewidth(2 * self.line_width + 1) # how to avoid this?!
self.get_widget_line(line).drl.line.set_alpha((np.exp(-self.line_width / 20))) # exponentially decreasing alpha
self.draw()
def _line_selector(self):
try:
self.rs.disconnect_events()
DraggableResizeableRectangle.lock = True
print('Rectangles are locked')
except:
print('Rectangles could not be locked')
print(self.__class__.__name__, ": Connecting Line Selector")
DraggableResizeableLine.lock = None
self.ls = RectangleSelector(self.axes_selector, self.line_selector_func, drawtype='line', useblit=True, button=[3])
def line_selector_func(self, eclick, erelease, cmap=mpl.cm.jet):
print(self.__class__.__name__, "Line Selector:")
print(self.__class__.__name__, "eclick: {} \n erelease: {}".format(eclick, erelease))
print()
x0, y0 = eclick.xdata, eclick.ydata
x1, y1 = erelease.xdata, erelease.ydata
cNorm = mpl.colors.Normalize(vmin=0, vmax=self.nColorsFromColormap)
scalarMap = mpl.cm.ScalarMappable(norm=cNorm, cmap=cmap)
color = scalarMap.to_rgba(len(self.drawn_lines) + 1)
text = 'line ' + str(len(self.drawn_lines))
line = AnnotatedLine(self.axes_selector,x0, y0, x1, y1, text=text, color=color)
self.drawn_lines_names.append(line.text)
self.drawn_lines.append(line)
self.canvas.draw()
def get_widget_line(self, line_name):
line_handle = None
for i, line in enumerate(self.drawn_lines):
if line.text == line_name:
line_handle = line