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


Python matplotlib.backends方法代码示例

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


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

示例1: switch_backend

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import backends [as 别名]
def switch_backend(newbackend):
    """
    Switch the default backend.  This feature is **experimental**, and
    is only expected to work switching to an image backend.  e.g., if
    you have a bunch of PostScript scripts that you want to run from
    an interactive ipython session, you may want to switch to the PS
    backend before running them to avoid having a bunch of GUI windows
    popup.  If you try to interactively switch from one GUI backend to
    another, you will explode.

    Calling this command will close all open windows.
    """
    close('all')
    global _backend_mod, new_figure_manager, draw_if_interactive, _show
    matplotlib.use(newbackend, warn=False, force=True)
    from matplotlib.backends import pylab_setup
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:pyplot.py

示例2: new_timer

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import backends [as 别名]
def new_timer(self, *args, **kwargs):
        """
        Creates a new backend-specific subclass of :class:`backend_bases.Timer`.
        This is useful for getting periodic events through the backend's native
        event loop. Implemented only for backends with GUIs.

        optional arguments:

        *interval*
          Timer interval in milliseconds
        *callbacks*
          Sequence of (func, args, kwargs) where func(*args, **kwargs) will
          be executed by the timer every *interval*.
        """
        return TimerMac(*args, **kwargs) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:17,代码来源:backend_macosx.py

示例3: new_timer

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import backends [as 别名]
def new_timer(self, *args, **kwargs):
        """
        Creates a new backend-specific subclass of `backend_bases.Timer`.
        This is useful for getting periodic events through the backend's native
        event loop. Implemented only for backends with GUIs.

        Other Parameters
        ----------------
        interval : scalar
            Timer interval in milliseconds
        callbacks : list
            Sequence of (func, args, kwargs) where ``func(*args, **kwargs)``
            will be executed by the timer every *interval*.
        """
        return TimerMac(*args, **kwargs) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:17,代码来源:backend_macosx.py

示例4: _get_running_interactive_framework

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import backends [as 别名]
def _get_running_interactive_framework():
    """
    Return the interactive framework whose event loop is currently running, if
    any, or "headless" if no event loop can be started, or None.

    Returns
    -------
    Optional[str]
        One of the following values: "qt5", "qt4", "gtk3", "wx", "tk",
        "macosx", "headless", ``None``.
    """
    QtWidgets = (sys.modules.get("PyQt5.QtWidgets")
                 or sys.modules.get("PySide2.QtWidgets"))
    if QtWidgets and QtWidgets.QApplication.instance():
        return "qt5"
    QtGui = (sys.modules.get("PyQt4.QtGui")
             or sys.modules.get("PySide.QtGui"))
    if QtGui and QtGui.QApplication.instance():
        return "qt4"
    Gtk = (sys.modules.get("gi.repository.Gtk")
           or sys.modules.get("pgi.repository.Gtk"))
    if Gtk and Gtk.main_level():
        return "gtk3"
    wx = sys.modules.get("wx")
    if wx and wx.GetApp():
        return "wx"
    tkinter = sys.modules.get("tkinter")
    if tkinter:
        for frame in sys._current_frames().values():
            while frame:
                if frame.f_code == tkinter.mainloop.__code__:
                    return "tk"
                frame = frame.f_back
    try:
        from matplotlib.backends import _macosx
    except ImportError:
        pass
    else:
        if _macosx.event_loop_is_running():
            return "macosx"
    if sys.platform.startswith("linux") and not os.environ.get("DISPLAY"):
        return "headless"
    return None 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:45,代码来源:__init__.py

示例5: pylab_setup

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import backends [as 别名]
def pylab_setup(name=None):
    """
    Return new_figure_manager, draw_if_interactive and show for pyplot.

    This provides the backend-specific functions that are used by pyplot to
    abstract away the difference between backends.

    Parameters
    ----------
    name : str, optional
        The name of the backend to use.  If `None`, falls back to
        ``matplotlib.get_backend()`` (which return :rc:`backend`).

    Returns
    -------
    backend_mod : module
        The module which contains the backend of choice

    new_figure_manager : function
        Create a new figure manager (roughly maps to GUI window)

    draw_if_interactive : function
        Redraw the current figure if pyplot is interactive

    show : function
        Show (and possibly block) any unshown figures.
    """
    # Import the requested backend into a generic module object.
    if name is None:
        name = matplotlib.get_backend()
    backend_name = (name[9:] if name.startswith("module://")
                    else "matplotlib.backends.backend_{}".format(name.lower()))
    backend_mod = importlib.import_module(backend_name)
    # Create a local Backend class whose body corresponds to the contents of
    # the backend module.  This allows the Backend class to fill in the missing
    # methods through inheritance.
    Backend = type("Backend", (_Backend,), vars(backend_mod))

    # Need to keep a global reference to the backend for compatibility reasons.
    # See https://github.com/matplotlib/matplotlib/issues/6092
    global backend
    backend = name

    _log.debug('backend %s version %s', name, Backend.backend_version)
    return (backend_mod,
            Backend.new_figure_manager,
            Backend.draw_if_interactive,
            Backend.show) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:50,代码来源:__init__.py

示例6: switch_backend

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import backends [as 别名]
def switch_backend(newbackend):
    """
    Close all open figures and set the Matplotlib backend.

    The argument is case-insensitive.  Switching to an interactive backend is
    possible only if no event loop for another interactive backend has started.
    Switching to and from non-interactive backends is always possible.

    Parameters
    ----------
    newbackend : str
        The name of the backend to use.
    """
    close("all")

    if newbackend is rcsetup._auto_backend_sentinel:
        for candidate in ["macosx", "qt5agg", "qt4agg", "gtk3agg", "gtk3cairo",
                          "tkagg", "wxagg", "agg", "cairo"]:
            try:
                switch_backend(candidate)
            except ImportError:
                continue
            else:
                rcParamsOrig['backend'] = candidate
                return

    backend_name = (
        newbackend[9:] if newbackend.startswith("module://")
        else "matplotlib.backends.backend_{}".format(newbackend.lower()))

    backend_mod = importlib.import_module(backend_name)
    Backend = type(
        "Backend", (matplotlib.backends._Backend,), vars(backend_mod))
    _log.debug("Loaded backend %s version %s.",
               newbackend, Backend.backend_version)

    required_framework = Backend.required_interactive_framework
    current_framework = \
        matplotlib.backends._get_running_interactive_framework()
    if (current_framework and required_framework
            and current_framework != required_framework):
        raise ImportError(
            "Cannot load backend {!r} which requires the {!r} interactive "
            "framework, as {!r} is currently running".format(
                newbackend, required_framework, current_framework))

    rcParams['backend'] = rcParamsDefault['backend'] = newbackend

    global _backend_mod, new_figure_manager, draw_if_interactive, _show
    _backend_mod = backend_mod
    new_figure_manager = Backend.new_figure_manager
    draw_if_interactive = Backend.draw_if_interactive
    _show = Backend.show

    # Need to keep a global reference to the backend for compatibility reasons.
    # See https://github.com/matplotlib/matplotlib/issues/6092
    matplotlib.backends.backend = newbackend 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:59,代码来源:pyplot.py

示例7: switch_backend

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import backends [as 别名]
def switch_backend(newbackend):
    """
    Close all open figures and set the Matplotlib backend.

    The argument is case-insensitive.  Switching to an interactive backend is
    possible only if no event loop for another interactive backend has started.
    Switching to and from non-interactive backends is always possible.

    Parameters
    ----------
    newbackend : str
        The name of the backend to use.
    """
    close("all")

    if newbackend is rcsetup._auto_backend_sentinel:
        for candidate in ["macosx", "qt5agg", "qt4agg", "gtk3agg", "gtk3cairo",
                          "tkagg", "wxagg", "agg", "cairo"]:
            try:
                switch_backend(candidate)
            except ImportError:
                continue
            else:
                rcParamsOrig['backend'] = candidate
                return

    backend_name = (
        newbackend[9:] if newbackend.startswith("module://")
        else "matplotlib.backends.backend_{}".format(newbackend.lower()))

    backend_mod = importlib.import_module(backend_name)
    Backend = type(
        "Backend", (matplotlib.backends._Backend,), vars(backend_mod))
    _log.debug("Loaded backend %s version %s.",
               newbackend, Backend.backend_version)

    required_framework = Backend.required_interactive_framework
    if required_framework is not None:
        current_framework = \
            matplotlib.backends._get_running_interactive_framework()
        if (current_framework and required_framework
                and current_framework != required_framework):
            raise ImportError(
                "Cannot load backend {!r} which requires the {!r} interactive "
                "framework, as {!r} is currently running".format(
                    newbackend, required_framework, current_framework))

    rcParams['backend'] = rcParamsDefault['backend'] = newbackend

    global _backend_mod, new_figure_manager, draw_if_interactive, _show
    _backend_mod = backend_mod
    new_figure_manager = Backend.new_figure_manager
    draw_if_interactive = Backend.draw_if_interactive
    _show = Backend.show

    # Need to keep a global reference to the backend for compatibility reasons.
    # See https://github.com/matplotlib/matplotlib/issues/6092
    matplotlib.backends.backend = newbackend 
开发者ID:holzschu,项目名称:python3_ios,代码行数:60,代码来源:pyplot.py

示例8: use

# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import backends [as 别名]
def use(arg, warn=True, force=False):
    """
    Set the matplotlib backend to one of the known backends.

    The argument is case-insensitive. *warn* specifies whether a
    warning should be issued if a backend has already been set up.
    *force* is an **experimental** flag that tells matplotlib to
    attempt to initialize a new backend by reloading the backend
    module.

    .. note::

        This function must be called *before* importing pyplot for
        the first time; or, if you are not using pyplot, it must be called
        before importing matplotlib.backends.  If warn is True, a warning
        is issued if you try and call this after pylab or pyplot have been
        loaded.  In certain black magic use cases, e.g.
        :func:`pyplot.switch_backend`, we are doing the reloading necessary to
        make the backend switch work (in some cases, e.g., pure image
        backends) so one can set warn=False to suppress the warnings.

    To find out which backend is currently set, see
    :func:`matplotlib.get_backend`.

    """
    # Lets determine the proper backend name first
    if arg.startswith('module://'):
        name = arg
    else:
        # Lowercase only non-module backend names (modules are case-sensitive)
        arg = arg.lower()
        name = validate_backend(arg)

    # Check if we've already set up a backend
    if 'matplotlib.backends' in sys.modules:
        # Warn only if called with a different name
        if (rcParams['backend'] != name) and warn:
            import matplotlib.backends
            warnings.warn(
                _use_error_msg.format(
                    backend=rcParams['backend'],
                    tb=matplotlib.backends._backend_loading_tb),
                stacklevel=2)

        # Unless we've been told to force it, just return
        if not force:
            return
        need_reload = True
    else:
        need_reload = False

    # Store the backend name
    rcParams['backend'] = name

    # If needed we reload here because a lot of setup code is triggered on
    # module import. See backends/__init__.py for more detail.
    if need_reload:
        reload(sys.modules['matplotlib.backends']) 
开发者ID:alvarobartt,项目名称:twitter-stock-recommendation,代码行数:60,代码来源:__init__.py


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