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


Python six.callable函数代码示例

本文整理汇总了Python中matplotlib.externals.six.callable函数的典型用法代码示例。如果您正苦于以下问题:Python callable函数的具体用法?Python callable怎么用?Python callable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: properties

    def properties(self):
        """
        return a dictionary mapping property name -> value
        """
        o = self.oorig
        getters = [name for name in dir(o)
                   if name.startswith('get_')
                   and six.callable(getattr(o, name))]
        getters.sort()
        d = dict()
        for name in getters:
            func = getattr(o, name)
            if self.is_alias(func):
                continue

            try:
                with warnings.catch_warnings():
                    warnings.simplefilter('ignore')
                    val = func()
            except:
                continue
            else:
                d[name[4:]] = val

        return d
开发者ID:JenniferWenHsu,项目名称:matplotlib,代码行数:25,代码来源:artist.py

示例2: _get_setters_and_targets

    def _get_setters_and_targets(self):
        """
        Get the attribute strings and a full path to where the setter
        is defined for all setters in an object.
        """

        setters = []
        for name in dir(self.o):
            if not name.startswith("set_"):
                continue
            o = getattr(self.o, name)
            if not six.callable(o):
                continue
            if len(inspect.getargspec(o)[0]) < 2:
                continue
            func = o
            if self.is_alias(func):
                continue
            source_class = self.o.__module__ + "." + self.o.__name__
            for cls in self.o.mro():
                if name in cls.__dict__:
                    source_class = cls.__module__ + "." + cls.__name__
                    break
            setters.append((name[4:], source_class + "." + name))
        return setters
开发者ID:fonnesbeck,项目名称:matplotlib,代码行数:25,代码来源:artist.py

示例3: pick

    def pick(self, mouseevent):
        """
        call signature::

          pick(mouseevent)

        each child artist will fire a pick event if *mouseevent* is over
        the artist and the artist has picker set
        """
        # Pick self
        if self.pickable():
            picker = self.get_picker()
            if six.callable(picker):
                inside, prop = picker(self, mouseevent)
            else:
                inside, prop = self.contains(mouseevent)
            if inside:
                self.figure.canvas.pick_event(mouseevent, self, **prop)

        # Pick children
        for a in self.get_children():
            # make sure the event happened in the same axes
            ax = getattr(a, "axes", None)
            if mouseevent.inaxes is None or ax is None or mouseevent.inaxes == ax:
                # we need to check if mouseevent.inaxes is None
                # because some objects associated with an axes (e.g., a
                # tick label) can be outside the bounding box of the
                # axes and inaxes will be None
                # also check that ax is None so that it traverse objects
                # which do no have an axes property but children might
                a.pick(mouseevent)
开发者ID:fonnesbeck,项目名称:matplotlib,代码行数:31,代码来源:artist.py

示例4: get_aliases

    def get_aliases(self):
        """
        Get a dict mapping *fullname* -> *alias* for each *alias* in
        the :class:`~matplotlib.artist.ArtistInspector`.

        e.g., for lines::

          {'markerfacecolor': 'mfc',
           'linewidth'      : 'lw',
          }

        """
        names = [
            name
            for name in dir(self.o)
            if (name.startswith("set_") or name.startswith("get_")) and six.callable(getattr(self.o, name))
        ]
        aliases = {}
        for name in names:
            func = getattr(self.o, name)
            if not self.is_alias(func):
                continue
            docstring = func.__doc__
            fullname = docstring[10:]
            aliases.setdefault(fullname[4:], {})[name[4:]] = None
        return aliases
开发者ID:fonnesbeck,项目名称:matplotlib,代码行数:26,代码来源:artist.py

示例5: get_window_extent

    def get_window_extent(self, renderer=None):
        if renderer is None:
            renderer = self.get_figure()._cachedRenderer

        if isinstance(self.bbox, BboxBase):
            return self.bbox
        elif six.callable(self.bbox):
            return self.bbox(renderer)
        else:
            raise ValueError("unknown type of bbox")
开发者ID:Perados,项目名称:matplotlib,代码行数:10,代码来源:image.py

示例6: set_picker

    def set_picker(self, p):
        """Sets the event picker details for the line.

        ACCEPTS: float distance in points or callable pick function
        ``fn(artist, event)``
        """
        if six.callable(p):
            self._contains = p
        else:
            self.pickradius = p
        self._picker = p
开发者ID:717524640,项目名称:matplotlib,代码行数:11,代码来源:lines.py

示例7: contains

    def contains(self, mouseevent):
        """Test whether the artist contains the mouse event.

        Returns the truth value and a dictionary of artist specific details of
        selection, such as which points are contained in the pick radius.  See
        individual artists for details.
        """
        if six.callable(self._contains):
            return self._contains(self, mouseevent)
        warnings.warn("'%s' needs 'contains' method" % self.__class__.__name__)
        return False, {}
开发者ID:fonnesbeck,项目名称:matplotlib,代码行数:11,代码来源:artist.py

示例8: contains

    def contains(self, mouseevent):
        """Test whether the mouse event occured within the image."""
        if six.callable(self._contains):
            return self._contains(self, mouseevent)

        if not self.get_visible():  # or self.get_figure()._renderer is None:
            return False, {}

        x, y = mouseevent.x, mouseevent.y
        inside = self.get_window_extent().contains(x, y)

        return inside, {}
开发者ID:Perados,项目名称:matplotlib,代码行数:12,代码来源:image.py

示例9: contains

    def contains(self, mouseevent):
        """Test whether the mouse event occured within the image."""
        if six.callable(self._contains):
            return self._contains(self, mouseevent)
        xmin, xmax, ymin, ymax = self.get_extent()
        xdata, ydata = mouseevent.x, mouseevent.y

        if xdata is not None and ydata is not None:
            inside = (xdata >= xmin) and (xdata <= xmax) and (ydata >= ymin) and (ydata <= ymax)
        else:
            inside = False

        return inside, {}
开发者ID:fonnesbeck,项目名称:matplotlib,代码行数:13,代码来源:image.py

示例10: revcmap

def revcmap(data):
    """Can only handle specification *data* in dictionary format."""
    data_r = {}
    for key, val in six.iteritems(data):
        if six.callable(val):
            valnew = _reverser(val)
            # This doesn't work: lambda x: val(1-x)
            # The same "val" (the first one) is used
            # each time, so the colors are identical
            # and the result is shades of gray.
        else:
            # Flip x and exchange the y values facing x = 0 and x = 1.
            valnew = [(1.0 - x, y1, y0) for x, y0, y1 in reversed(val)]
        data_r[key] = valnew
    return data_r
开发者ID:AndreLobato,项目名称:matplotlib,代码行数:15,代码来源:cm.py

示例11: findobj

    def findobj(self, match=None, include_self=True):
        """
        Find artist objects.

        Recursively find all :class:`~matplotlib.artist.Artist` instances
        contained in self.

        *match* can be

          - None: return all objects contained in artist.

          - function with signature ``boolean = match(artist)``
            used to filter matches

          - class instance: e.g., Line2D.  Only return artists of class type.

        If *include_self* is True (default), include self in the list to be
        checked for a match.

        """
        if match is None:  # always return True

            def matchfunc(x):
                return True

        elif cbook.issubclass_safe(match, Artist):

            def matchfunc(x):
                return isinstance(x, match)

        elif six.callable(match):
            matchfunc = match
        else:
            raise ValueError("match must be None, a matplotlib.artist.Artist " "subclass, or a callable")

        artists = []

        for c in self.get_children():
            if matchfunc(c):
                artists.append(c)
            artists.extend([thisc for thisc in c.findobj(matchfunc, include_self=False) if matchfunc(thisc)])

        if include_self and matchfunc(self):
            artists.append(self)
        return artists
开发者ID:fonnesbeck,项目名称:matplotlib,代码行数:45,代码来源:artist.py

示例12: contains

    def contains(self, mouseevent):
        """Test whether the mouse event occurred in the table.

        Returns T/F, {}
        """
        if six.callable(self._contains):
            return self._contains(self, mouseevent)

        # TODO: Return index of the cell containing the cursor so that the user
        # doesn't have to bind to each one individually.
        if self._cachedRenderer is not None:
            boxes = [self._cells[pos].get_window_extent(self._cachedRenderer)
                     for pos in six.iterkeys(self._cells)
                     if pos[0] >= 0 and pos[1] >= 0]
            bbox = Bbox.union(boxes)
            return bbox.contains(mouseevent.x, mouseevent.y), {}
        else:
            return False, {}
开发者ID:Marcovaldong,项目名称:matplotlib,代码行数:18,代码来源:table.py

示例13: __init__

    def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
                 save_count=None, **kwargs):
        if fargs:
            self._args = fargs
        else:
            self._args = ()
        self._func = func

        # Amount of framedata to keep around for saving movies. This is only
        # used if we don't know how many frames there will be: in the case
        # of no generator or in the case of a callable.
        self.save_count = save_count

        # Set up a function that creates a new iterable when needed. If nothing
        # is passed in for frames, just use itertools.count, which will just
        # keep counting from 0. A callable passed in for frames is assumed to
        # be a generator. An iterable will be used as is, and anything else
        # will be treated as a number of frames.
        if frames is None:
            self._iter_gen = itertools.count
        elif six.callable(frames):
            self._iter_gen = frames
        elif iterable(frames):
            self._iter_gen = lambda: iter(frames)
            if hasattr(frames, '__len__'):
                self.save_count = len(frames)
        else:
            self._iter_gen = lambda: xrange(frames).__iter__()
            self.save_count = frames

        # If we're passed in and using the default, set it to 100.
        if self.save_count is None:
            self.save_count = 100

        self._init_func = init_func

        # Needs to be initialized so the draw functions work without checking
        self._save_seq = []

        TimedAnimation.__init__(self, fig, **kwargs)

        # Need to reset the saved seq, since right now it will contain data
        # for a single frame from init, which is not what we want.
        self._save_seq = []
开发者ID:Allen-smith,项目名称:ctf-tools,代码行数:44,代码来源:animation.py

示例14: __call__

    def __call__(self, x, pos=None):
        locator_unit_scale = float(self._locator._get_unit())
        fmt = self.defaultfmt

        # Pick the first scale which is greater than the locator unit.
        for possible_scale in sorted(self.scaled):
            if possible_scale >= locator_unit_scale:
                fmt = self.scaled[possible_scale]
                break

        if isinstance(fmt, six.string_types):
            self._formatter = DateFormatter(fmt, self._tz)
            result = self._formatter(x, pos)
        elif six.callable(fmt):
            result = fmt(x, pos)
        else:
            raise TypeError('Unexpected type passed to {!r}.'.formatter(self))

        return result
开发者ID:AndreLobato,项目名称:matplotlib,代码行数:19,代码来源:dates.py

示例15: _update_gc

    def _update_gc(self, gc, new_gc_dict):
        """
        Update the given GraphicsCollection with the given
        dictionary of properties. The keys in the dictionary are used to
        identify the appropriate set_ method on the gc.

        """
        new_gc_dict = new_gc_dict.copy()

        dashes = new_gc_dict.pop("dashes", None)
        if dashes:
            gc.set_dashes(**dashes)

        for k, v in six.iteritems(new_gc_dict):
            set_method = getattr(gc, 'set_' + k, None)
            if set_method is None or not six.callable(set_method):
                raise AttributeError('Unknown property {0}'.format(k))
            set_method(v)
        return gc
开发者ID:ethanhelfman,项目名称:InstaGet,代码行数:19,代码来源:patheffects.py


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