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')
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) 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')
def show(mainloop=True): """ Show all the figures and enter the gtk main loop This should be the last line of your script """ for manager in Gcf.get_all_fig_managers(): manager.window.show() if mainloop and gtk.main_level() == 0 and len(Gcf.get_all_fig_managers()) > 0: gtk.main()
def show(mainloop=True): """ Show all the figures and enter the gtk main loop This should be the last line of your script """ for manager in Gcf.get_all_fig_managers(): manager.window.show() if mainloop and gtk.main_level() == 0 and \ len(Gcf.get_all_fig_managers())>0: gtk.main()
def show(close=True, block=None): """Show all figures as PNG payloads sent to the Jupyter frontend. Parameters ---------- close : Close figures after sending block : Not used. """ for figure_manager in Gcf.get_all_fig_managers(): fig = figure_manager.canvas.figure send_fig_to_kernel(fig) if close and Gcf.get_all_fig_managers(): matplotlib.pyplot.close('all')
def __call__(self, **kwargs): managers = Gcf.get_all_fig_managers() if not managers: return for manager in managers: manager.show(**kwargs)
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 makes the figure in focus the # active one. 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: Gcf.figs.pop(manager.num, None)
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
def show(): figmanager = Gcf.get_active() if figmanager is not None: figmanager.show() else: for manager in Gcf.get_all_fig_managers(): manager.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)
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()
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
def test_save_load_no_excess_plot(): result = SingleToneSpectroscopyResult("test_no_excess_plot", "test") frequencies = linspace(0, 20000, 201) currents = np.linspace(0, 0.5, 20) XX, YY = np.meshgrid(frequencies, currents) S21s = np.cos(XX)+ 1j*np.sin(YY) data = {"Frequency [Hz]":frequencies, "Current [A]":currents, "data":S21s} result.set_data(data) result._anim = None result.set_start_datetime(datetime.datetime(2005, 7, 14, 12, 30)) result._parameter_names = ["Frequency [Hz]", "Current [A]"] result.save() result1 = MeasurementResult.load("test", "test_no_excess_plot") # assert not hasattr(result1, "_lines") # assert not hasattr(result1, "_fit_lines") # assert np.all(result1.get_data()["data"] == data["data"]) # assert np.all(result1.get_data()["echo_delay"] == data["echo_delay"]) assert len(Gcf.get_all_fig_managers()) == 0
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)
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)
def show(): """ This over-rides matplotlibs `show` function to save instead of rendering to the screen. """ allfm = Gcf.get_all_fig_managers() for fcount, fm in enumerate(allfm): fm.canvas.figure.savefig('%s_%02i.png' % (figure_basename, fcount + 1))
def secureShow(): '''Show the graphs; but don't crash if no graphs exist.''' from matplotlib._pylab_helpers import Gcf #see if there are any diagrams if len(Gcf.get_all_fig_managers()) == 0: return #enter mainloop show()
def show(): """ This over-rides matplotlibs `show` function to save instead of rendering to the screen. """ allfm = Gcf.get_all_fig_managers() for fcount, fm in enumerate(allfm): fm.canvas.figure.savefig('%s_%02i.png' % (figure_basename, fcount+1))
def show(): """ Show all the figures and enter the fltk mainloop This should be the last line of your script """ for manager in Gcf.get_all_fig_managers(): manager.show() Fltk.Fl.run()
def show(): try: for manager in Gcf.get_all_fig_managers(): canvas = manager.canvas canvas.draw() string = canvas.to_txt() print(string) finally: pass
def draw_if_interactive(): """ For image backends - is not required For GUI backends - this should be overriden if drawing should be done in interactive python mode """ for manager in Gcf.get_all_fig_managers(): # draw figure managers' views manager.canvas.draw()
def print_figure(self, fname, **kwargs): try: for manager in Gcf.get_all_fig_managers(): canvas = manager.canvas canvas.draw() string = canvas.to_txt() print(string, file=open(fname + '.txt', 'w', encoding="utf-8"), end='') finally: pass
def show(block=None): """ For image backends - is not required. For GUI backends - show() is usually the last line of a pyplot script and tells the backend that it is time to draw. In interactive mode, this should do nothing. """ for manager in Gcf.get_all_fig_managers(): # do something to display the GUI pass
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 """ for manager in Gcf.get_all_fig_managers(): pass
def test_save_load_no_excess_plot(result): result.save() result1 = MeasurementResult.load("test", "test_no_excess_plot") # assert np.all(result1.get_data()["data"] == result1.get_data()["data"]) # assert np.all(result1.get_data()["echo_delay"] == result1.get_data()["echo_delay"]) assert len(Gcf.get_all_fig_managers()) == 0 MeasurementResult.delete("test", "test_no_excess_plot", delete_all=True)
def show(*, block=None): """ For image backends - is not required. For GUI backends - show() is usually the last line of a pyplot script and tells the backend that it is time to draw. In interactive mode, this should do nothing. """ for manager in Gcf.get_all_fig_managers(): # do something to display the GUI pass
def show(mainloop=True): """ Show all the figures and enter the gtk main loop This should be the last line of your script """ for manager in Gcf.get_all_fig_managers(): manager.window.show() if mainloop and gtk.main_level() == 0: if gtk.pygtk_version >= (2,4,0): gtk.main() else: gtk.mainloop()
def show(block=None): """ 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 """ for manager in Gcf.get_all_fig_managers(): manager.canvas.send_deepforge_update() pass
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 """ for manager in Gcf.get_all_fig_managers(): # do something to display the GUI pass
def secureShow(): """Show the graphs; but don't crash if no graphs exist.""" from matplotlib._pylab_helpers import Gcf # see if there are any diagrams if len(Gcf.get_all_fig_managers()) == 0: return # matplotlib bug: show thinks there is already a QT mainloop show._needmain = True # enter mainloop show()
def __call__(self, **kwargs): debug("show() called with args %s" % kwargs) managers = Gcf.get_all_fig_managers() if not managers: debug( "Error: Managers list in `Gcf.get_all_fig_managers()` is empty" ) return for manager in managers: manager.show(**kwargs)
def show(close=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. """ if close is None: close = InlineBackend.instance().close_figures try: for figure_manager in Gcf.get_all_fig_managers(): display(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')
def ishow(): """ Show all the figures and enter the fltk mainloop in another thread This allows to keep hand in interractive python session Warning: does not work under windows This should be the last line of your script """ for manager in Gcf.get_all_fig_managers(): manager.show() if show._needmain: thread.start_new_thread(Fltk_run_interactive,()) show._needmain = False
def ishow(): """ Show all the figures and enter the fltk mainloop in another thread This allows to keep hand in interractive python session Warning: does not work under windows This should be the last line of your script """ for manager in Gcf.get_all_fig_managers(): manager.show() if show._needmain: thread.start_new_thread(Fltk_run_interactive, ()) show._needmain = False
def mainloop(self): WebAggApplication.initialize() for manager in Gcf.get_all_fig_managers(): url = "http://127.0.0.1:{0}/{1}/".format( WebAggApplication.port, manager.num) if rcParams['webagg.open_in_browser']: import webbrowser webbrowser.open(url) else: print("To view figure, visit {0}".format(url)) WebAggApplication.start()
def show(): try: for manager in Gcf.get_all_fig_managers(): canvas = manager.canvas canvas.draw() string = canvas.to_txt() print(string) # display(HTML("<div style=\"font-size:2px; line-height:90%;\"><tt>" + string + "</tt></div>")) finally: #if close and Gcf.get_all_fig_managers(): # matplotlib.pyplot.close('all') pass
def mainloop(): managers = Gcf.get_all_fig_managers() if managers: first_manager = managers[0] manager_class = type(first_manager) if manager_class._owns_mainloop: return manager_class._owns_mainloop = True try: first_manager.window.mainloop() finally: manager_class._owns_mainloop = False
def show(*, block=None): """ For image backends - is not required. For GUI backends - show() is usually the last line of a pyplot script and tells the backend that it is time to draw. In interactive mode, this should do nothing. """ #manager = Gcf.get_active() if matplotlib.is_interactive(): return for manager in Gcf.get_all_fig_managers(): manager.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 """ for manager in Gcf.get_all_fig_managers(): # do something to display the GUI # show_basic_window() paint_manager = _get_paint_manager(manager.canvas.figure) print(paint_manager)
def show(): """ Show all the figures and enter the qt main loop This should be the last line of your script """ for manager in Gcf.get_all_fig_managers(): manager.window.show() if DEBUG: print 'Inside show' figManager = Gcf.get_active() if figManager != None: figManager.canvas.draw() if _create_qApp.qAppCreatedHere: qt.qApp.exec_loop()
def show(close=True): """Show all figures as SVG payloads sent to the IPython clients. Parameters ---------- close : bool, optional If true, a ``plt.close('all')`` call is automatically issued after sending all the SVG figures. """ for figure_manager in Gcf.get_all_fig_managers(): send_svg_canvas(figure_manager.canvas) if close: matplotlib.pyplot.close('all')
def show(): """ Show all the figures and enter the fltk mainloop This should be the last line of your script """ for manager in Gcf.get_all_fig_managers(): manager.show() #mainloop, if an fltk program exist no need to call that #threaded (and interractive) version if show._needmain: Fltk.Fl.run() show._needmain = False
def show(close=True): """Show all figures as SVG payloads sent to the IPython clients. Parameters ---------- close : bool, optional If true, a ``plt.close('all')`` call is automatically issued after sending all the SVG figures. If this is set, the figures will entirely removed from the internal list of figures. """ for figure_manager in Gcf.get_all_fig_managers(): send_svg_figure(figure_manager.canvas.figure) if close: matplotlib.pyplot.close('all')
def show(close=False): """Show all figures as SVG payloads sent to the IPython clients. Parameters ---------- close : bool, optional If true, a ``plt.close('all')`` call is automatically issued after sending all the SVG figures. If this is set, the figures will entirely removed from the internal list of figures. """ for figure_manager in Gcf.get_all_fig_managers(): send_svg_figure(figure_manager.canvas.figure) if close: matplotlib.pyplot.close("all")
def show(*, block=None): """ For image backends - is not required. For GUI backends - show() is usually the last line of a pyplot script and tells the backend that it is time to draw. In interactive mode, this should do nothing. """ for manager in Gcf.get_all_fig_managers(): # do something to display the GUI # t = threading.Thread(target=manager.show()) # t.daemon = True # t.start() manager.show() Gcf.destroy(manager.num)
def __call__(self, close=None, block=None, **kwargs): if close is None: close = mpl_config.get('close') try: managers = Gcf.get_all_fig_managers() if not managers: return # Tell zeppelin that the output will be html using the %html magic # We want to do this only once to avoid seeing "%html" printed # directly to the outout when multiple figures are displayed from # one paragraph. if mpl_config.get('angular'): print('%angular') else: print('%html') # Show all open figures for manager in managers: manager.show(**kwargs) finally: # This closes all the figures if close is set to True. if close and Gcf.get_all_fig_managers(): Gcf.destroy_all()
def connection_info(): """ Return a string showing the figure and connection status for the backend. This is intended as a diagnostic tool, and not for general use. """ from matplotlib._pylab_helpers import Gcf result = [] for manager in Gcf.get_all_fig_managers(): fig = manager.canvas.figure result.append("{0} - {0}".format((fig.get_label() or "Figure {0}".format(manager.num)), manager.web_sockets)) result.append("Figures pending show: {0}".format(len(Gcf._activeQue))) return "\n".join(result)
def connection_info(): """ Return a string showing the figure and connection status for the backend. This is intended as a diagnostic tool, and not for general use. """ result = [ '{fig} - {socket}'.format(fig=(manager.canvas.figure.get_label() or "Figure {}".format(manager.num)), socket=manager.web_sockets) for manager in Gcf.get_all_fig_managers() ] if not is_interactive(): result.append(f'Figures pending show: {len(Gcf.figs)}') return '\n'.join(result)
def connection_info(): """ Return a string showing the figure and connection status for the backend. This is intended as a diagnostic tool, and not for general use. """ result = [] for manager in Gcf.get_all_fig_managers(): fig = manager.canvas.figure result.append('{0} - {0}'.format((fig.get_label() or "Figure {0}".format(manager.num)), manager.web_sockets)) if not is_interactive(): result.append('Figures pending show: {0}'.format(len(Gcf._activeQue))) return '\n'.join(result)
def show(close=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. """ if close is None: close = InlineBackendConfig.instance().close_figures for figure_manager in Gcf.get_all_fig_managers(): send_figure(figure_manager.canvas.figure) if close: matplotlib.pyplot.close('all') show._to_draw = []
def flush_figures(): """Send all figures that changed This is meant to be called automatically and will call show() if, during prior code execution, there had been any calls to draw_if_interactive. This function is meant to be used as a post_execute callback in IPython, so user-caused errors are handled with showtraceback() instead of being allowed to raise. If this function is not called from within IPython, then these exceptions will raise. """ if not show._draw_called: return if InlineBackend.instance().close_figures: # ignore the tracking, just draw and close all figures try: return show(True) except Exception as e: # safely show traceback if in IPython, else raise try: get_ipython except NameError: raise e else: get_ipython().showtraceback() return try: # exclude any figures that were closed: active = set([fm.canvas.figure for fm in Gcf.get_all_fig_managers()]) for fig in [ fig for fig in show._to_draw if fig in active ]: try: display(fig) except Exception as e: # safely show traceback if in IPython, else raise try: get_ipython except NameError: raise e else: get_ipython().showtraceback() break finally: # clear flags for next round show._to_draw = [] show._draw_called = False
def align_figures(): import matplotlib from matplotlib._pylab_helpers import Gcf from IPython.display import display_html import base64 from ipykernel.pylab.backend_inline import show images = [] for figure_manager in Gcf.get_all_fig_managers(): fig = figure_manager.canvas.figure png = get_ipython().display_formatter.format(fig)[0]['image/png'] src = base64.encodestring(png).decode() images.append('<img style="margin:0" align="left" src="data:image/png;base64,{}"/>'.format(src)) html = "{}".format("".join(images)) show._draw_called = False matplotlib.pyplot.close('all') display_html(html, raw=True)