本文整理汇总了Python中matplotlib._pylab_helpers.Gcf类的典型用法代码示例。如果您正苦于以下问题:Python Gcf类的具体用法?Python Gcf怎么用?Python Gcf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gcf类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show
def show():
""" Show all the figures """
for manager in Gcf.get_all_fig_managers():
manager.window.show()
figManager = Gcf.get_active()
if figManager != None:
figManager.canvas.draw()
示例2: show
def show(block=True, layout="", open_plot=True):
"""
This show is typically called via pyplot.show.
In general usage a script will have a sequence of figure creation followed by a pyplot.show which
effectively blocks and leaves the figures open for the user.
We suspect this blocking is because the mainloop thread of the GUI is not setDaemon and thus halts
python termination.
To simulate this we create a non daemon dummy thread and instruct the user to use Ctrl-C to finish...
"""
Gcf.get_active().canvas.draw()
# update the current figure
# open the browser with the current active figure shown...
# if not _test and open_plot:
# try:
# webbrowser.open_new_tab(h5m.url + "/" + str(layout))
# except:
# print "Failed to open figure page in your browser. Please browse to " + h5m.url + "/" + str(Gcf.get_active().canvas.figure.number)
if block and not _test:
print "Showing figures. Hit Ctrl-C to finish script and close figures..."
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
if not _quiet:
print "Shutting down..."
示例3: show
def show(close=None, block=None):
"""Show all figures as SVG/PNG payloads sent to the IPython clients.
Parameters
----------
close : bool, optional
If true, a ``plt.close('all')`` call is automatically issued after
sending all the figures. If this is set, the figures will entirely
removed from the internal list of figures.
block : Not used.
The `block` parameter is a Matplotlib experimental parameter.
We accept it in the function signature for compatibility with other
backends.
"""
if close is None:
close = InlineBackend.instance().close_figures
try:
for figure_manager in Gcf.get_all_fig_managers():
display(
figure_manager.canvas.figure,
metadata=_fetch_figure_metadata(figure_manager.canvas.figure)
)
finally:
show._to_draw = []
# only call close('all') if any to close
# close triggers gc.collect, which can be slow
if close and Gcf.get_all_fig_managers():
matplotlib.pyplot.close('all')
示例4: _widgetclosed
def _widgetclosed( self ):
if self.window._destroying: return
self.window._destroying = True
try:
Gcf.destroy(self.num)
except AttributeError:
pass
示例5: fig_visibility_changed
def fig_visibility_changed(self):
"""
Make a notification in the global figure manager that
plot visibility was changed. This method is added to this
class so that it can be wrapped in a QAppThreadCall.
"""
Gcf.figure_visibility_changed(self.num)
示例6: _widgetclosed
def _widgetclosed(self):
if self.window._destroying:
return
self.window._destroying = True
map(self.canvas.mpl_disconnect, self._cids)
try:
Gcf.destroy(self.num)
except AttributeError:
pass
示例7: set_window_title
def set_window_title(self, title):
self.window.setWindowTitle(title)
# We need to add a call to the figure manager here to call
# notify methods when a figure is renamed, to update our
# plot list.
Gcf.figure_title_changed(self.num)
# For the workbench we also keep the label in sync, this is
# to allow getting a handle as plt.figure('Figure Name')
self.canvas.figure.set_label(title)
示例8: savefig
def savefig(self, figure=None, **kwargs):
"""
Saves a :class:`~matplotlib.figure.Figure` to this file as a new page.
Any other keyword arguments are passed to
:meth:`~matplotlib.figure.Figure.savefig`.
Parameters
----------
figure : :class:`~matplotlib.figure.Figure` or int, optional
Specifies what figure is saved to file. If not specified, the
active figure is saved. If a :class:`~matplotlib.figure.Figure`
instance is provided, this figure is saved. If an int is specified,
the figure instance to save is looked up by number.
"""
if not isinstance(figure, Figure):
if figure is None:
manager = Gcf.get_active()
else:
manager = Gcf.get_fig_manager(figure)
if manager is None:
raise ValueError("No figure {}".format(figure))
figure = manager.canvas.figure
try:
orig_canvas = figure.canvas
figure.canvas = FigureCanvasPgf(figure)
width, height = figure.get_size_inches()
if self._n_figures == 0:
self._write_header(width, height)
else:
# \pdfpagewidth and \pdfpageheight exist on pdftex, xetex, and
# luatex<0.85; they were renamed to \pagewidth and \pageheight
# on luatex>=0.85.
self._file.write(
br'\newpage'
br'\ifdefined\pdfpagewidth\pdfpagewidth'
br'\else\pagewidth\fi=%ain'
br'\ifdefined\pdfpageheight\pdfpageheight'
br'\else\pageheight\fi=%ain'
b'%%\n' % (width, height)
)
figure.savefig(self._file, format="pgf", **kwargs)
self._n_figures += 1
finally:
figure.canvas = orig_canvas
示例9: draw_if_interactive
def draw_if_interactive():
'''Handle whether or not the backend is in interactive mode or not.
'''
if matplotlib.is_interactive():
figManager = Gcf.get_active()
if figManager:
figManager.canvas.draw_idle()
示例10: show
def show():
"""
For image backends - is not required
For GUI backends - show() is usually the last line of a pylab script and
tells the backend that it is time to draw. In interactive mode, this may
be a do nothing func. See the GTK backend for an example of how to handle
interactive versus batch mode
"""
global plotnumber
global lastfile
global filename_template
global outdir
for manager in Gcf.get_all_fig_managers():
# do something to display the GUI
pass
lastfile = filename_template % plotnumber
outpath = os.path.join(outdir, lastfile)
if not os.path.exists(outdir):
raise IOError("No such directory %s " % outdir)
if setdpi:
matplotlib.pyplot.savefig(outpath, dpi=setdpi)
else:
matplotlib.pyplot.savefig(outpath)
plotnumber = plotnumber + 1
return plotnumber - 1
示例11: pastefig
def pastefig(*figs):
"""Paste one or more figures into the console workspace.
If no arguments are given, all available figures are pasted. If the
argument list contains references to invalid figures, a warning is printed
but the function continues pasting further figures.
Parameters
----------
figs : tuple
A tuple that can contain any mixture of integers and figure objects.
"""
if not figs:
show(close=False)
else:
fig_managers = Gcf.get_all_fig_managers()
fig_index = dict( [(fm.canvas.figure, fm.canvas) for fm in fig_managers]
+ [ (fm.canvas.figure.number, fm.canvas) for fm in fig_managers] )
for fig in figs:
canvas = fig_index.get(fig)
if canvas is None:
print('Warning: figure %s not available.' % fig)
else:
send_svg_canvas(canvas)
示例12: getfigs
def getfigs(*fig_nums):
"""Get a list of matplotlib figures by figure numbers.
If no arguments are given, all available figures are returned. If the
argument list contains references to invalid figures, a warning is printed
but the function continues pasting further figures.
Parameters
----------
figs : tuple
A tuple of ints giving the figure numbers of the figures to return.
"""
from matplotlib._pylab_helpers import Gcf
if not fig_nums:
fig_managers = Gcf.get_all_fig_managers()
return [fm.canvas.figure for fm in fig_managers]
else:
figs = []
for num in fig_nums:
f = Gcf.figs.get(num)
if f is None:
print('Warning: figure %s not available.' % num)
else:
figs.append(f.canvas.figure)
return figs
示例13: open
def open(self, fignum):
self.fignum = int(fignum)
manager = Gcf.get_fig_manager(self.fignum)
manager.add_web_socket(self)
_, _, w, h = manager.canvas.figure.bbox.bounds
manager.resize(w, h)
self.on_message('{"type":"refresh"}')
示例14: __call__
def __call__(self, **kwargs):
managers = Gcf.get_all_fig_managers()
if not managers:
return
for manager in managers:
manager.show(**kwargs)
示例15: show
def show(*args, block=None, **kwargs):
if args or kwargs:
cbook.warn_deprecated(
"3.1", message="Passing arguments to show(), other than "
"passing 'block' by keyword, is deprecated %(since)s, and "
"support for it will be removed %(removal)s.")
## TODO: something to do when keyword block==False ?
from matplotlib._pylab_helpers import Gcf
managers = Gcf.get_all_fig_managers()
if not managers:
return
interactive = is_interactive()
for manager in managers:
manager.show()
# plt.figure adds an event which puts the figure in focus
# in the activeQue. Disable this behaviour, as it results in
# figures being put as the active figure after they have been
# shown, even in non-interactive mode.
if hasattr(manager, '_cidgcf'):
manager.canvas.mpl_disconnect(manager._cidgcf)
if not interactive and manager in Gcf._activeQue:
Gcf._activeQue.remove(manager)