def set_notebook_plot_backend(backend='inline'): """ Set matplotlib backend within a Jupyter Notebook shell. Ths function has the same effect as the line magic ``%matplotlib [backend]`` but is called as a function and includes a check to determine whether the code is running in a notebook shell, so that it can safely be used within a normal python script since it has no effect when not running in a notebook shell. Parameters ---------- backend : string, optional (default 'inline') Name of backend to be passed to the ``%matplotlib`` line magic command """ from sporco.util import in_notebook if in_notebook(): # See https://stackoverflow.com/questions/35595766 get_ipython().run_line_magic('matplotlib', backend)
def set_notebook_plot_backend(backend='inline'): """ Set matplotlib backend within a Jupyter Notebook shell. Ths function has the same effect as the line magic ``%matplotlib [backend]`` but is called as a function and includes a check to determine whether the code is running in a notebook shell, so that it can safely be used within a normal python script since it has no effect when not running in a notebook shell. Parameters ---------- backend : string, optional (default 'inline') Name of backend to be passed to the ``%matplotlib`` line magic command """ from sporco.util import in_notebook if in_notebook(): # See https://stackoverflow.com/questions/35595766 get_ipython().run_line_magic('matplotlib', backend)
def config_notebook_plotting(): """ Configure plotting functions for inline plotting within a Jupyter Notebook shell. This function has no effect when not within a notebook shell, and may therefore be used within a normal python script. """ # Check whether running within a notebook shell and have # not already monkey patched the plot function from sporco.util import in_notebook module = sys.modules[__name__] if in_notebook() and module.plot.__name__ == 'plot': # Set inline backend (i.e. %matplotlib inline) if in a notebook shell set_notebook_plot_backend() # Replace plot function with a wrapper function that discards # its return value (within a notebook with inline plotting, plots # are duplicated if the return value from the original function is # not assigned to a variable) plot_original = module.plot def plot_wrap(*args, **kwargs): plot_original(*args, **kwargs) module.plot = plot_wrap # Replace surf function with a wrapper function that discards # its return value (see comment for plot function) surf_original = module.surf def surf_wrap(*args, **kwargs): surf_original(*args, **kwargs) module.surf = surf_wrap # Replace contour function with a wrapper function that discards # its return value (see comment for plot function) contour_original = module.contour def contour_wrap(*args, **kwargs): contour_original(*args, **kwargs) module.contour = contour_wrap # Replace imview function with a wrapper function that discards # its return value (see comment for plot function) imview_original = module.imview def imview_wrap(*args, **kwargs): imview_original(*args, **kwargs) module.imview = imview_wrap # Disable figure show method (results in a warning if used within # a notebook with inline plotting) import matplotlib.figure def show_disable(self): pass matplotlib.figure.Figure.show = show_disable
def test_27(self): val = util.in_notebook() assert val is True or val is False
from sporco import cuda from sporco.admm import cbpdn import sporco.linalg as spl import sporco.metric as spm # If running in a notebook, try to use wurlitzer so that output from the CUDA # code will be properly captured in the notebook. from contextlib import contextmanager @contextmanager def null_context_manager(): yield if util.in_notebook(): try: from wurlitzer import sys_pipes except: sys_pipes = null_context_manager else: sys_pipes = null_context_manager """ Load example image. """ img = util.ExampleImages().image('barbara.png', scaled=True, gray=True, idxexp=np.s_[10:522, 100:612]) """
def test_27(self): val = util.in_notebook() assert val is True or val is False
def config_notebook_plotting(): """ Configure plotting functions for inline plotting within a Jupyter Notebook shell. This function has no effect when not within a notebook shell, and may therefore be used within a normal python script. """ # Check whether running within a notebook shell and have # not already monkey patched the plot function from sporco.util import in_notebook module = sys.modules[__name__] if in_notebook() and module.plot.__name__ == 'plot': # Set inline backend (i.e. %matplotlib inline) if in a notebook shell set_notebook_plot_backend() # Replace plot function with a wrapper function that discards # its return value (within a notebook with inline plotting, plots # are duplicated if the return value from the original function is # not assigned to a variable) plot_original = module.plot def plot_wrap(*args, **kwargs): plot_original(*args, **kwargs) module.plot = plot_wrap # Replace surf function with a wrapper function that discards # its return value (see comment for plot function) surf_original = module.surf def surf_wrap(*args, **kwargs): surf_original(*args, **kwargs) module.surf = surf_wrap # Replace contour function with a wrapper function that discards # its return value (see comment for plot function) contour_original = module.contour def contour_wrap(*args, **kwargs): contour_original(*args, **kwargs) module.contour = contour_wrap # Replace imview function with a wrapper function that discards # its return value (see comment for plot function) imview_original = module.imview def imview_wrap(*args, **kwargs): imview_original(*args, **kwargs) module.imview = imview_wrap # Disable figure show method (results in a warning if used within # a notebook with inline plotting) import matplotlib.figure def show_disable(self): pass matplotlib.figure.Figure.show = show_disable