Python matplotlib.pyplot.isinteractive() Examples
The following are 9
code examples of matplotlib.pyplot.isinteractive().
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.pyplot
, or try the search function
.
Example #1
Source File: idlplot.py From astrolibpy with GNU General Public License v3.0 | 6 votes |
def exceptionDecorator(func): def wrapper(*args, **kwargs): try: isInteractive = plt.isinteractive() # switch to non-interactive mode #matplotlib.interactive(False) ret = func(*args, **kwargs) matplotlib.interactive(isInteractive) draw_if_interactive() return ret except Exception as exc: # switch back matplotlib.interactive(isInteractive) raise wrapper.__doc__ = func.__doc__ return wrapper
Example #2
Source File: easyplot.py From easyplot with MIT License | 5 votes |
def redraw(self): """ Redraw plot. Use after custom user modifications of axes & fig objects """ if plt.isinteractive(): fig = self.kwargs['fig'] #Redraw figure if it was previously closed prior to updating it if not plt.fignum_exists(fig.number): fig.show() fig.canvas.draw() else: print('redraw() is unsupported in non-interactive plotting mode!')
Example #3
Source File: spypylab.py From spectral with MIT License | 5 votes |
def set_mpl_interactive(): '''Ensure matplotlib is in interactive mode.''' import matplotlib.pyplot as plt if not plt.isinteractive(): plt.interactive(True)
Example #4
Source File: test_analyzers.py From bindsnet with GNU Affero General Public License v3.0 | 5 votes |
def test_init(self): ma = MatplotlibAnalyzer() assert plt.isinteractive() ta = TensorboardAnalyzer("./logs/init") # check to ensure path was written assert os.path.isdir("./logs/init") # check to ensure we can write data ta.writer.add_scalar("init_scalar", 100.0, 0) ta.writer.close()
Example #5
Source File: general.py From marvin with BSD 3-Clause "New" or "Revised" License | 5 votes |
def turn_off_ion(show_plot=True): ''' Turns off the Matplotlib plt interactive mode Context manager to temporarily disable the interactive Matplotlib plotting functionality. Useful for only returning Figure and Axes objects Parameters: show_plot (bool): If True, turns off the plotting Example: >>> >>> with turn_off_ion(show_plot=False): >>> do_some_stuff >>> ''' plt_was_interactive = plt.isinteractive() if not show_plot and plt_was_interactive: plt.ioff() fignum_init = plt.get_fignums() yield plt if show_plot: plt.ioff() plt.show() else: for ii in plt.get_fignums(): if ii not in fignum_init: plt.close(ii) # Restores original ion() status if plt_was_interactive and not plt.isinteractive(): plt.ion()
Example #6
Source File: test_analyzers.py From bindsnet with GNU Affero General Public License v3.0 | 5 votes |
def test_init(self): ma = MatplotlibAnalyzer() assert plt.isinteractive() ta = TensorboardAnalyzer("./logs/init") # check to ensure path was written assert os.path.isdir("./logs/init") # check to ensure we can write data ta.writer.add_scalar("init_scalar", 100.0, 0) ta.writer.close()
Example #7
Source File: im_utils.py From deep-transfer with Apache License 2.0 | 5 votes |
def tensor_imshow(tensor, title=None): inp = tensor.numpy().transpose((1, 2, 0)) inp = np.clip(inp, 0, 1) plt.imshow(inp) if title is not None: plt.title(title) if plt.isinteractive(): plt.ioff() plt.show() # import torch # tensor_imshow(torch.randn(3, 256, 512), 'pytorch tensor')
Example #8
Source File: easyplot.py From easyplot with MIT License | 4 votes |
def add_plot(self, *args, **kwargs): """ Add plot using supplied parameters and existing instance parameters Creates new Figure and Axes object if 'fig' and 'ax' parameters not supplied. Stores references to all Line2D objects plotted in self.line_list. Arguments ========= *args : Supports format plot(y), plot(x, y), plot(x, y, 'b-'). x, y and format string are passed through for plotting **kwargs : Plot parameters. Refer to __init__ docstring for details """ self._update(*args, **kwargs) # Create figure and axes if needed if self.kwargs['fig'] is None: if not self.isnewargs: return # Don't create fig, ax yet if no x, y data provided self.kwargs['fig'] = plt.figure(figsize=self.kwargs['figsize'], dpi=self.kwargs['dpi']) self.kwargs['ax'] = self.kwargs['fig'].gca() self.kwargs['fig'].add_axes(self.kwargs['ax']) ax, fig = self.kwargs['ax'], self.kwargs['fig'] ax.ticklabel_format(useOffset=False) # Prevent offset notation in plots # Apply axes functions if present in kwargs for kwarg in self.kwargs: if kwarg in self._ax_funcs: # eg: f = getattr(ax,'set_title'); f('new title') func = getattr(ax, self._ax_funcs[kwarg]) func(self.kwargs[kwarg]) # Add plot only if new args passed to this instance if self.isnewargs: # Create updated name, value dict to pass to plot method plot_kwargs = {kwarg: self.kwargs[kwarg] for kwarg in self._plot_kwargs if kwarg in self.kwargs} line, = ax.plot(*self.args, **plot_kwargs) self.line_list.append(line) # Display legend if required if self.kwargs['showlegend']: legend_kwargs = {kwarg: self.kwargs[kwarg] for kwarg in self._legend_kwargs if kwarg in self.kwargs} leg = ax.legend(**legend_kwargs) if leg is not None: leg.draggable(state=True) if 'fontsize' in self.kwargs: self.set_fontsize(self.kwargs['fontsize']) self._delete_uniqueparams() # Clear unique parameters from kwargs list if plt.isinteractive(): # Only redraw canvas in interactive mode self.redraw()
Example #9
Source File: _tqdm_gui.py From Tautulli with GNU General Public License v3.0 | 4 votes |
def __init__(self, *args, **kwargs): import matplotlib as mpl import matplotlib.pyplot as plt from collections import deque kwargs['gui'] = True super(tqdm_gui, self).__init__(*args, **kwargs) # Initialize the GUI display if self.disable or not kwargs['gui']: return warn('GUI is experimental/alpha', TqdmExperimentalWarning) self.mpl = mpl self.plt = plt self.sp = None # Remember if external environment uses toolbars self.toolbar = self.mpl.rcParams['toolbar'] self.mpl.rcParams['toolbar'] = 'None' self.mininterval = max(self.mininterval, 0.5) self.fig, ax = plt.subplots(figsize=(9, 2.2)) # self.fig.subplots_adjust(bottom=0.2) if self.total: self.xdata = [] self.ydata = [] self.zdata = [] else: self.xdata = deque([]) self.ydata = deque([]) self.zdata = deque([]) self.line1, = ax.plot(self.xdata, self.ydata, color='b') self.line2, = ax.plot(self.xdata, self.zdata, color='k') ax.set_ylim(0, 0.001) if self.total: ax.set_xlim(0, 100) ax.set_xlabel('percent') self.fig.legend((self.line1, self.line2), ('cur', 'est'), loc='center right') # progressbar self.hspan = plt.axhspan(0, 0.001, xmin=0, xmax=0, color='g') else: # ax.set_xlim(-60, 0) ax.set_xlim(0, 60) ax.invert_xaxis() ax.set_xlabel('seconds') ax.legend(('cur', 'est'), loc='lower left') ax.grid() # ax.set_xlabel('seconds') ax.set_ylabel((self.unit if self.unit else 'it') + '/s') if self.unit_scale: plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0)) ax.yaxis.get_offset_text().set_x(-0.15) # Remember if external environment is interactive self.wasion = plt.isinteractive() plt.ion() self.ax = ax