当前位置: 首页>>代码示例>>Python>>正文


Python CheckButtons.disconnect_events方法代码示例

本文整理汇总了Python中matplotlib.widgets.CheckButtons.disconnect_events方法的典型用法代码示例。如果您正苦于以下问题:Python CheckButtons.disconnect_events方法的具体用法?Python CheckButtons.disconnect_events怎么用?Python CheckButtons.disconnect_events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.widgets.CheckButtons的用法示例。


在下文中一共展示了CheckButtons.disconnect_events方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AttributeSelector

# 需要导入模块: from matplotlib.widgets import CheckButtons [as 别名]
# 或者: from matplotlib.widgets.CheckButtons import disconnect_events [as 别名]
class AttributeSelector(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, rax, raxmap, labels, labelcolors):
        self.canvas = ax.figure.canvas
        self.collection = collection
        self.labelcolors = [colorConverter.to_rgba(c) for c in labelcolors]
        self.labels = labels

        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.sfc = self.fc.copy()

        self.state = [False] * len(labels)
        self.check = CheckButtons(rax,labels,self.state)
        self.check.on_clicked(self.onclick)
        self.raxmap = raxmap
        self.ind = []
        
    def updateselection(self, color):
        if len(self.ind) > 0:
            self.sfc[self.ind, :] = color
        self.collection.set_facecolors(self.sfc)
        self.canvas.draw_idle()

    def onclick(self, label):
        self.ind = raxmap[label]
        labelindex = self.labels.index(label)
        self.state[labelindex] = not self.state[labelindex]
        if self.state[labelindex]:
            color = self.labelcolors[labelindex]
        else:
            color = self.fc[self.ind,:]
        
        self.updateselection(color)

    def disconnect(self):
        self.check.disconnect_events()
        #self.fc[:, -1] = 1
        self.collection.set_facecolors(self.fc)
        self.canvas.draw_idle()
开发者ID:georgedimitriadis,项目名称:themeaningofbrain,代码行数:69,代码来源:attributeselector.py


注:本文中的matplotlib.widgets.CheckButtons.disconnect_events方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。