本文整理汇总了Python中matplotlib.pyplot.isinteractive方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.isinteractive方法的具体用法?Python pyplot.isinteractive怎么用?Python pyplot.isinteractive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.isinteractive方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exceptionDecorator
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import isinteractive [as 别名]
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
示例2: redraw
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import isinteractive [as 别名]
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!')
示例3: set_mpl_interactive
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import isinteractive [as 别名]
def set_mpl_interactive():
'''Ensure matplotlib is in interactive mode.'''
import matplotlib.pyplot as plt
if not plt.isinteractive():
plt.interactive(True)
示例4: test_init
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import isinteractive [as 别名]
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()
示例5: turn_off_ion
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import isinteractive [as 别名]
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()
示例6: tensor_imshow
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import isinteractive [as 别名]
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')
示例7: add_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import isinteractive [as 别名]
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()
示例8: __init__
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import isinteractive [as 别名]
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