當前位置: 首頁>>代碼示例>>Python>>正文


Python matplotlib.get_backend方法代碼示例

本文整理匯總了Python中matplotlib.get_backend方法的典型用法代碼示例。如果您正苦於以下問題:Python matplotlib.get_backend方法的具體用法?Python matplotlib.get_backend怎麽用?Python matplotlib.get_backend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在matplotlib的用法示例。


在下文中一共展示了matplotlib.get_backend方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: args_validation

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def args_validation(args):

    # # Test to see what matplotlib backend is setup
    backend = matplotlib.get_backend()
    if not backend == 'TkAgg':
        log.warning('{} matplotlib backend in use. This graph generation was tested with "agg", bugs may lie ahead...'.format(backend))

    # # Test to see if we should use defaults
    if args.graphtype == 'all':
        args.no_zero = __no_zero__
        args.width = __width__
        args.no_log = __g_log__
        args.no_order = __no_order__
        args.colours = __colours__

    try:
        args.colours[0] = matplotlib.colors.to_rgba(args.colours[0])
        args.colours[1] = matplotlib.colors.to_rgba(args.colours[1])
    except ValueError as e:
        raise ArgValidationEx('Error parsing --colours: {}'.format(e)) 
開發者ID:geekscrapy,項目名稱:binGraph,代碼行數:22,代碼來源:graph.py

示例2: switch_backend

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def switch_backend(backend):

    def switch_backend_decorator(func):

        @functools.wraps(func)
        def backend_switcher(*args, **kwargs):
            try:
                prev_backend = mpl.get_backend()
                matplotlib.testing.setup()
                plt.switch_backend(backend)
                return func(*args, **kwargs)
            finally:
                plt.switch_backend(prev_backend)

        return backend_switcher

    return switch_backend_decorator 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:19,代碼來源:decorators.py

示例3: draw

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def draw(self, filename=None, verbose=False):
        self._draw_regs()
        self._draw_ops(verbose)
        _xl = - self._style.margin[0]
        _xr = self._cond['xmax'] + self._style.margin[1]
        _yb = - self._cond['ymax'] - self._style.margin[2] + 1 - 0.5
        _yt = self._style.margin[3] + 0.5
        self.ax.set_xlim(_xl, _xr)
        self.ax.set_ylim(_yb, _yt)

        # update figure size
        fig_w = _xr - _xl
        fig_h = _yt - _yb
        if self._style.figwidth < 0.0:
            self._style.figwidth = fig_w * self._scale * self._style.fs / 72 / WID
        self.figure.set_size_inches(self._style.figwidth, self._style.figwidth * fig_h / fig_w)

        if filename:
            self.figure.savefig(filename, dpi=self._style.dpi,
                                bbox_inches='tight', facecolor=self.figure.get_facecolor())
        if self.return_fig:
            if get_backend() in ['module://ipykernel.pylab.backend_inline',
                                 'nbAgg']:
                plt.close(self.figure)
            return self.figure 
開發者ID:Qiskit,項目名稱:qiskit-terra,代碼行數:27,代碼來源:matplotlib.py

示例4: show_inline_matplotlib_plots

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def show_inline_matplotlib_plots():
    """Show matplotlib plots immediately if using the inline backend.

    With ipywidgets 6.0, matplotlib plots don't work well with interact when
    using the inline backend that comes with ipykernel. Basically, the inline
    backend only shows the plot after the entire cell executes, which does not
    play well with drawing plots inside of an interact function. See
    https://github.com/jupyter-widgets/ipywidgets/issues/1181/ and
    https://github.com/ipython/ipython/issues/10376 for more details. This
    function displays any matplotlib plots if the backend is the inline backend.
    """
    if 'matplotlib' not in sys.modules:
        # matplotlib hasn't been imported, nothing to do.
        return

    try:
        import matplotlib as mpl
        from ipykernel.pylab.backend_inline import flush_figures
    except ImportError:
        return

    if mpl.get_backend() == 'module://ipykernel.pylab.backend_inline':
        flush_figures() 
開發者ID:luckystarufo,項目名稱:pySINDy,代碼行數:25,代碼來源:interaction.py

示例5: flush_inline_matplotlib_plots

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def flush_inline_matplotlib_plots():
    """
    Flush matplotlib plots immediately, rather than asynchronously.
    Basically, the inline backend only shows the plot after the entire 
    cell executes, which means we can't easily use a contextmanager to
    suppress displaying it. See https://github.com/jupyter-widgets/ipywidgets/issues/1181/ 
    and https://github.com/ipython/ipython/issues/10376 for more details. This
    function displays flushes any pending matplotlib plots if we are using
    the inline backend.

    Stolen from https://github.com/jupyter-widgets/ipywidgets/blob/4cc15e66d5e9e69dac8fc20d1eb1d7db825d7aa2/ipywidgets/widgets/interaction.py#L35
    """
    if 'matplotlib' not in sys.modules:
        # matplotlib hasn't been imported, nothing to do.
        return

    try:
        import matplotlib as mpl
        from ipykernel.pylab.backend_inline import flush_figures
    except ImportError:
        return

    if mpl.get_backend() == 'module://ipykernel.pylab.backend_inline':
        flush_figures() 
開發者ID:data-8,項目名稱:Gofer-Grader,代碼行數:26,代碼來源:utils.py

示例6: move_plt_figure

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def move_plt_figure(fig, x, y):
    """Move matplotlib figure to position
    https://stackoverflow.com/a/37999370

    Args:
        fig: Figure handle
        x: Position x
        y: Position y
    """
    plt_backend = matplotlib.get_backend()
    if plt_backend == 'TkAgg':
        fig.canvas.manager.window.wm_geometry("+%d+%d" % (x, y))
    elif plt_backend == 'WXAgg':
        fig.canvas.manager.window.SetPosition((x, y))
    else:
        # This works for QT and GTK
        # You can also use window.setGeometry
        fig.canvas.manager.window.move(x, y) 
開發者ID:kujason,項目名稱:monopsr,代碼行數:20,代碼來源:vis_utils.py

示例7: flush_inline_matplotlib_plots

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def flush_inline_matplotlib_plots():
    """
    Flush matplotlib plots immediately, rather than asynchronously.
    Basically, the inline backend only shows the plot after the entire
    cell executes, which means we can't easily use a contextmanager to
    suppress displaying it. See https://github.com/jupyter-widgets/ipywidgets/issues/1181/
    and https://github.com/ipython/ipython/issues/10376 for more details. This
    function displays flushes any pending matplotlib plots if we are using
    the inline backend.
    Stolen from https://github.com/jupyter-widgets/ipywidgets/blob/4cc15e66d5e9e69dac8fc20d1eb1d7db825d7aa2/ipywidgets/widgets/interaction.py#L35
    """
    if 'matplotlib' not in sys.modules:
        # matplotlib hasn't been imported, nothing to do.
        return

    try:
        import matplotlib as mpl
        from ipykernel.pylab.backend_inline import flush_figures
    except ImportError:
        return
    # except KeyError:
    #     return

    if mpl.get_backend() == 'module://ipykernel.pylab.backend_inline':
        flush_figures() 
開發者ID:ucbds-infra,項目名稱:otter-grader,代碼行數:27,代碼來源:gofer.py

示例8: switch_backend

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def switch_backend(backend):
    # Local import to avoid a hard nose dependency and only incur the
    # import time overhead at actual test-time.
    def switch_backend_decorator(func):
        @functools.wraps(func)
        def backend_switcher(*args, **kwargs):
            try:
                prev_backend = mpl.get_backend()
                matplotlib.testing.setup()
                plt.switch_backend(backend)
                result = func(*args, **kwargs)
            finally:
                plt.switch_backend(prev_backend)
            return result

        return _copy_metadata(func, backend_switcher)
    return switch_backend_decorator 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:19,代碼來源:decorators.py

示例9: show

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def show(self, **kwargs):
        self.plot_if_not_done_yet()

        # in a notebook the plot method need not to be called explicitly
        if not in_notebook() and matplotlib.get_backend() != "agg":
            plt.show(**kwargs)
            plt.close() 
開發者ID:msu-coinlab,項目名稱:pymoo,代碼行數:9,代碼來源:plot.py

示例10: get_compatible_pyplot

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def get_compatible_pyplot(backend=None, debug=True):
    """Make the backend of MPL compatible.

    In Travis Mac distributions, python is not installed as a framework. This
    means that using the TkAgg backend is the best solution (so it doesn't
    try to use the mac OS backend by default).

    Parameters
    ----------
    backend : str, optional (default="TkAgg")
        The backend to default to.

    debug : bool, optional (default=True)
        Whether to log the existing backend to stderr.
    """
    import matplotlib

    # If the backend provided is None, just default to
    # what's already being used.
    existing_backend = matplotlib.get_backend()
    if backend is not None:
        # Can this raise?...
        matplotlib.use(backend)

        # Print out the new backend
        if debug:
            sys.stderr.write("Currently using '%s' MPL backend, "
                             "switching to '%s' backend%s"
                             % (existing_backend, backend, os.linesep))

    # If backend is not set via env variable, but debug is
    elif debug:
        sys.stderr.write("Using '%s' MPL backend%s"
                         % (existing_backend, os.linesep))

    from matplotlib import pyplot as plt
    return plt 
開發者ID:alkaline-ml,項目名稱:pmdarima,代碼行數:39,代碼來源:matplotlib.py

示例11: on_new_train_step

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def on_new_train_step(self, sample_id, data_buffer):
        """ This is the listener main function, which gives it the ability to
        'listen' for the caller. Whenever the EvaluationVisualiser should 
        be aware of some new data, the caller will invoke this function,
        passing the new data buffer.
        
        Parameters
        ----------
        sample_id: int
            The current sample id.

        data_buffer: EvaluationDataBuffer
            A buffer containing evaluation data for a single training / visualization step.
            
        Raises
        ------
        ValueError: If an exception is raised during the draw operation.
         
        """

        try:
            current_time = time.time()
            self._clear_annotations()
            self._update_plots(sample_id, data_buffer)

            # To mitigate re-drawing overhead for fast models use frame counter (default = 5 frames).
            # To avoid slow refresh rate in slow models use a time limit (default = 1 sec).
            if (self._frame_cnt == 5) or (current_time - self._last_draw_timestamp > 1):
                plt.subplots_adjust(right=0.72, bottom=0.22)  # Adjust subplots to include metrics annotations
                if get_backend() == 'nbAgg':
                    self.fig.canvas.draw()    # Force draw in'notebook' backend
                plt.pause(1e-9)
                self._frame_cnt = 0
                self._last_draw_timestamp = current_time
            else:
                self._frame_cnt += 1
        except BaseException as exception:
            raise ValueError('Failed when trying to draw plot. Exception: {} | Type: {}'.
                             format(exception, type(exception).__name__)) 
開發者ID:scikit-multiflow,項目名稱:scikit-multiflow,代碼行數:41,代碼來源:evaluation_visualizer.py

示例12: _import_matplotlib

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def _import_matplotlib():
    """Import matplotlib safely."""
    # make sure that the Agg backend is set before importing any
    # matplotlib
    import matplotlib
    matplotlib.use('agg')
    matplotlib_backend = matplotlib.get_backend().lower()

    filterwarnings("ignore", category=UserWarning,
                   message='Matplotlib is currently using agg, which is a'
                           ' non-GUI backend, so cannot show the figure.')

    if matplotlib_backend != 'agg':
        raise ExtensionError(
            "Sphinx-Gallery relies on the matplotlib 'agg' backend to "
            "render figures and write them to files. You are "
            "currently using the {} backend. Sphinx-Gallery will "
            "terminate the build now, because changing backends is "
            "not well supported by matplotlib. We advise you to move "
            "sphinx_gallery imports before any matplotlib-dependent "
            "import. Moving sphinx_gallery imports at the top of "
            "your conf.py file should fix this issue"
            .format(matplotlib_backend))

    import matplotlib.pyplot as plt
    return matplotlib, plt 
開發者ID:sphinx-gallery,項目名稱:sphinx-gallery,代碼行數:28,代碼來源:scrapers.py

示例13: switch_backend

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def switch_backend(backend):

    def switch_backend_decorator(func):
        def backend_switcher(*args, **kwargs):
            try:
                prev_backend = mpl.get_backend()
                mpl.rcdefaults()
                plt.switch_backend(backend)
                result = func(*args, **kwargs)
            finally:
                plt.switch_backend(prev_backend)
            return result

        return nose.tools.make_decorator(func)(backend_switcher)
    return switch_backend_decorator 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:17,代碼來源:test_backend_pgf.py

示例14: move_figure

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def move_figure(f, x, y):
    """Move figure's upper left corner to pixel (x, y)"""
    backend = matplotlib.get_backend()
    if backend == 'TkAgg':
        f.canvas.manager.window.wm_geometry("+%d+%d" % (x, y))
    elif backend == 'WXAgg':
        f.canvas.manager.window.SetPosition((x, y))
    else:
        # This works for QT and GTK
        # You can also use window.setGeometry
        f.canvas.manager.window.move(x, y) 
開發者ID:cbaziotis,項目名稱:keras-utilities,代碼行數:13,代碼來源:ui.py

示例15: _set_mpl_backend

# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import get_backend [as 別名]
def _set_mpl_backend():
    """Make sure that we don't get DISPLAY problems when running without X
    on unices
    Code imported from nilearn (nilearn/nilearn/plotting/__init__.py)
    """
    # We are doing local imports here to avoid polluting our namespace
    import matplotlib
    import os
    import sys
    # Set the backend to a non-interactive one for unices without X
    if ((os.name == 'posix' and 'DISPLAY' not in os.environ
         and not (sys.platform == 'darwin'
                  and matplotlib.get_backend() == 'MacOSX'))
            or 'DISPLAY' in os.environ and os.environ['DISPLAY'] == '-1'):
        matplotlib.use('Agg') 
開發者ID:X-DataInitiative,項目名稱:tick,代碼行數:17,代碼來源:__init__.py


注:本文中的matplotlib.get_backend方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。