• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python six.callable函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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:
                val = func()
            except:
                continue
            else:
                d[name[4:]] = val

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


示例17: update

    def update(self, props):
        """
        Update the properties of this :class:`Artist` from the
        dictionary *prop*.
        """
        store = self.eventson
        self.eventson = False
        changed = False

        for k, v in six.iteritems(props):
            if k in ["axes"]:
                setattr(self, k, v)
            else:
                func = getattr(self, "set_" + k, None)
                if func is None or not six.callable(func):
                    raise AttributeError("Unknown property %s" % k)
                func(v)
            changed = True
        self.eventson = store
        if changed:
            self.pchanged()
            self.stale = True
开发者ID:fonnesbeck,项目名称:matplotlib,代码行数:22,代码来源:artist.py


示例18: wrap

    def wrap(self, fmt, func, level='helpful', always=True):
        """
        return a callable function that wraps func and reports it
        output through the verbose handler if current verbosity level
        is higher than level

        if always is True, the report will occur on every function
        call; otherwise only on the first time the function is called
        """
        assert six.callable(func)

        def wrapper(*args, **kwargs):
            ret = func(*args, **kwargs)

            if (always or not wrapper._spoke):
                spoke = self.report(fmt % ret, level)
                if not wrapper._spoke:
                    wrapper._spoke = spoke
            return ret
        wrapper._spoke = False
        wrapper.__doc__ = func.__doc__
        return wrapper
开发者ID:jheinen,项目名称:matplotlib,代码行数:22,代码来源:__init__.py


示例19: findobj

    def findobj(self, match=None):
        """
        Recursively find all :class:`matplotlib.artist.Artist`
        instances contained in *self*.

        If *match* is not None, it can be

          - function with signature ``boolean = match(artist)``

          - class instance: e.g., :class:`~matplotlib.lines.Line2D`

        used to filter matches.
        """
        if match is None:  # always return True
            def matchfunc(x):
                return True
        elif issubclass(match, Artist):
            def matchfunc(x):
                return isinstance(x, match)
        elif six.callable(match):
            matchfunc = func
        else:
            raise ValueError('match must be None, an '
                             '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)
                            if matchfunc(thisc)])

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


示例20: _update_property

        def _update_property(self, k, v):
            """sorting out how to update property (setter or setattr)

            Parameters
            ----------
            k : str
                The name of property to update
            v : obj
                The value to assign to the property
            Returns
            -------
            ret : obj or None
                If using a `set_*` method return it's return, else None.
            """
            k = k.lower()
            # white list attributes we want to be able to update through
            # art.update, art.set, setp
            if k in {'axes'}:
                return setattr(self, k, v)
            else:
                func = getattr(self, 'set_' + k, None)
                if func is None or not six.callable(func):
                    raise AttributeError('Unknown property %s' % k)
                return func(v)
开发者ID:JenniferWenHsu,项目名称:matplotlib,代码行数:24,代码来源:artist.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python six.iteritems函数代码示例发布时间:2022-05-27
下一篇:
Python dviread.find_tex_file函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap