Python matplotlib.backends() Examples
The following are 18
code examples of matplotlib.backends().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib
, or try the search function
.
Example #1
Source File: pyplot.py From twitter-stock-recommendation with MIT License | 7 votes |
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()
Example #2
Source File: pyplot.py From Computable with MIT License | 6 votes |
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()
Example #3
Source File: pyplot.py From neural-network-animation with MIT License | 6 votes |
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()
Example #4
Source File: pyplot.py From matplotlib-4-abaqus with MIT License | 6 votes |
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()
Example #5
Source File: backend_macosx.py From neural-network-animation with MIT License | 5 votes |
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)
Example #6
Source File: backend_macosx.py From matplotlib-4-abaqus with MIT License | 5 votes |
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)
Example #7
Source File: backend_macosx.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #8
Source File: backend_macosx.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #9
Source File: backend_macosx.py From ImageFusion with MIT License | 5 votes |
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)
Example #10
Source File: backend_macosx.py From coffeegrindsize with MIT License | 5 votes |
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)
Example #11
Source File: backend_macosx.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #12
Source File: backend_macosx.py From Computable with MIT License | 5 votes |
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)
Example #13
Source File: __init__.py From GraphicDesignPatternByPython with MIT License | 4 votes |
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
Example #14
Source File: __init__.py From GraphicDesignPatternByPython with MIT License | 4 votes |
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)
Example #15
Source File: pyplot.py From GraphicDesignPatternByPython with MIT License | 4 votes |
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
Example #16
Source File: pyplot.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 4 votes |
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
Example #17
Source File: pyplot.py From coffeegrindsize with MIT License | 4 votes |
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
Example #18
Source File: __init__.py From twitter-stock-recommendation with MIT License | 4 votes |
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'])