当前位置: 首页>>代码示例>>Python>>正文


Python display.clear_output方法代码示例

本文整理汇总了Python中IPython.display.clear_output方法的典型用法代码示例。如果您正苦于以下问题:Python display.clear_output方法的具体用法?Python display.clear_output怎么用?Python display.clear_output使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPython.display的用法示例。


在下文中一共展示了display.clear_output方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_display_progress_fn

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def get_display_progress_fn(showProgress):
    """
    Create and return a progress-displaying function if `showProgress == True`
    and it's run within an interactive environment.
    """

    def _is_interactive():
        import __main__ as main
        return not hasattr(main, '__file__')

    if _is_interactive() and showProgress:
        try:
            from IPython.display import clear_output

            def _display_progress(i, N, filename):
                _time.sleep(0.001); clear_output()
                print("Loading %s: %.0f%%" % (filename, 100.0 * float(i) / float(N)))
                _sys.stdout.flush()
        except:
            def _display_progress(i, N, f): pass
    else:
        def _display_progress(i, N, f): pass

    return _display_progress 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:26,代码来源:stdinput.py

示例2: plot_durations

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def plot_durations():
    plt.figure(2)
    plt.clf()
    durations_t = torch.tensor(episode_durations, dtype=torch.float)
    plt.title('Training...')
    plt.xlabel('Episode')
    plt.ylabel('Duration')
    plt.plot(durations_t.numpy())
    # Take 100 episode averages and plot them too
    if len(durations_t) >= 100:
        means = durations_t.unfold(0, 100, 1).mean(1).view(-1)
        means = torch.cat((torch.zeros(99), means))
        plt.plot(means.numpy())

    plt.pause(0.001)
    if is_ipython:
        display.clear_output(wait=True)
        display.display(plt.gcf())

#%% Training loop 
开发者ID:gutouyu,项目名称:ML_CIA,代码行数:22,代码来源:Reinforcement Learning DQN.py

示例3: __init__

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def __init__(self, draw_func=None, out_file=None,
                 jupyter=False, pause=False, clear=True, delay=0, disable=False,
                 video_args=None, _patch_delay=0.05):
        self.jupyter = jupyter
        self.disable = disable
        if self.jupyter and not self.disable:
            from IPython import display
            self._jupyter_clear_output = display.clear_output
            self._jupyter_display = display.display
            callback = self.draw_jupyter_frame
        else:
            callback = None
        self.anim = Animation(draw_func, callback=callback)
        self.out_file = out_file
        self.pause = pause
        self.clear = clear
        self.delay = delay
        if video_args is None:
            video_args = {}
        self.video_args = video_args
        self._patch_delay = _patch_delay 
开发者ID:cduck,项目名称:drawSvg,代码行数:23,代码来源:animation.py

示例4: interactive_output

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def interactive_output(f, controls):
    """Connect widget controls to a function.

    This function does not generate a user interface for the widgets (unlike `interact`).
    This enables customisation of the widget user interface layout.
    The user interface layout must be defined and displayed manually.
    """

    out = Output()
    def observer(change):
        kwargs = {k:v.value for k,v in controls.items()}
        show_inline_matplotlib_plots()
        with out:
            clear_output(wait=True)
            f(**kwargs)
            show_inline_matplotlib_plots()
    for k,w in controls.items():
        w.observe(observer, 'value')
    show_inline_matplotlib_plots()
    observer(None)
    return out 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:23,代码来源:interaction.py

示例5: plot

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def plot(self, show=True):
        kwargs = {
            e["encoding"]: _get_plot_command(e) for e in self.settings["encodings"]
        }
        kwargs = {k: v for k, v in kwargs.items() if v is not None}

        mark_opts = {k: v for k, v in self.settings["mark"].items()}
        mark = mark_opts.pop("mark")
        Chart_mark = getattr(altair.Chart(self.df), mark)
        self.chart = Chart_mark(**mark_opts).encode(**kwargs)
        if show and self.show:
            clear_output()
            display("Updating...")
            with io.StringIO() as f:
                self.chart.save(f, format="svg")
                f.seek(0)
                html = f.read()
            clear_output()
            display(self.controller)
            display(SVG(html)) 
开发者ID:altair-viz,项目名称:altair_widgets,代码行数:22,代码来源:widget.py

示例6: clear_output

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def clear_output(self, *pargs, **kwargs):
        """
        Clear the content of the output widget.

        Parameters
        ----------

        wait: bool
            If True, wait to clear the output until new output is
            available to replace it. Default: False
        """
        with self:
            clear_output(*pargs, **kwargs)

    # PY3: Force passing clear_output and clear_kwargs as kwargs 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:17,代码来源:widget_output.py

示例7: UpdateFromPIL

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def UpdateFromPIL(self, new_img):
    from io import BytesIO
    from IPython import display
    display.clear_output(wait=True)
    image = BytesIO()
    new_img.save(image, format='png')
    display.display(display.Image(image.getvalue())) 
开发者ID:google,项目名称:ffn,代码行数:9,代码来源:inference.py

示例8: _update_trait

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def _update_trait(self, p_name, p_value, widget=None):
        p_obj = self.parameterized.params(p_name)
        widget = self._widgets[p_name] if widget is None else widget
        if isinstance(p_value, tuple):
            p_value, size = p_value

            if isinstance(size, tuple) and len(size) == 2:
                if isinstance(widget, ipywidgets.Image):
                    widget.width = size[0]
                    widget.height = size[1]
                else:
                    widget.layout.min_width = '%dpx' % size[0]
                    widget.layout.min_height = '%dpx' % size[1]

        if isinstance(widget, Output):
            if isinstance(p_obj, HTMLView) and p_value:
                p_value = HTML(p_value)
            with widget:
                # clear_output required for JLab support
                # in future handle.update(p_value) should be sufficient
                handle = self._display_handles.get(p_name)
                if handle:
                    clear_output(wait=True)
                    handle.display(p_value)
                else:
                    handle = display(p_value, display_id=p_name+self._id)
                    self._display_handles[p_name] = handle
        else:
            widget.value = p_value 
开发者ID:ioam,项目名称:paramnb,代码行数:31,代码来源:__init__.py

示例9: plot_live

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def plot_live(self, *args, **kwargs):
        """Live plotting loop for jupyter notebook, which automatically updates
        (an) in-line matplotlib graph(s). Will create a new plot as specified by input
        arguments, or will update (an) existing plot(s)."""
        if self.wait_for_data():
            if not (self.plots):
                self.plot(*args, **kwargs)
            while not self.worker.should_stop():
                self.update_plot()
            display.clear_output(wait=True)
            if self.worker.is_alive():
                self.worker.terminate()
            self.scribe.stop() 
开发者ID:ralph-group,项目名称:pymeasure,代码行数:15,代码来源:experiment.py

示例10: update_plot

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def update_plot(self):
        """Update the plots in the plots list with new data from the experiment.data
        pandas dataframe."""
        try:
            tasks = []
            self.data
            for plot in self.plots:
                ax = plot['ax']
                if plot['type'] == 'plot':
                    x, y = plot['args'][0], plot['args'][1]
                    if type(y) == str:
                        y = [y]
                    for yname, line in zip(y, ax.lines):
                        self.update_line(ax, line, x, yname)
                if plot['type'] == 'pcolor':
                    x, y, z = plot['x'], plot['y'], plot['z']
                    update_pcolor(ax, x, y, z)

            display.clear_output(wait=True)
            display.display(*self.figs)
            time.sleep(0.1)
        except KeyboardInterrupt:
            display.clear_output(wait=True)
            display.display(*self.figs)
            self._user_interrupt = True 
开发者ID:ralph-group,项目名称:pymeasure,代码行数:27,代码来源:experiment.py

示例11: capture

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def capture(self, clear_output=False, *clear_args, **clear_kwargs):
        """
        Decorator to capture the stdout and stderr of a function.

        Parameters
        ----------

        clear_output: bool
            If True, clear the content of the output widget at every
            new function call. Default: False

        wait: bool
            If True, wait to clear the output until new output is
            available to replace it. This is only used if clear_output
            is also True.
            Default: False
        """
        def capture_decorator(func):
            @wraps(func)
            def inner(*args, **kwargs):
                if clear_output:
                    self.clear_output(*clear_args, **clear_kwargs)
                with self:
                    return func(*args, **kwargs)
            return inner
        return capture_decorator 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:28,代码来源:widget_output.py

示例12: update

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def update(self, *args):
        """
        Call the interact function and update the output widget with
        the result of the function call.

        Parameters
        ----------
        *args : ignored
            Required for this method to be used as traitlets callback.
        """
        self.kwargs = {}
        if self.manual:
            self.manual_button.disabled = True
        try:
            show_inline_matplotlib_plots()
            with self.out:
                if self.clear_output:
                    clear_output(wait=True)
                for widget in self.kwargs_widgets:
                    value = widget.get_interact_value()
                    self.kwargs[widget._kwarg] = value
                self.result = self.f(**self.kwargs)
                show_inline_matplotlib_plots()
                if self.auto_display and self.result is not None:
                    display(self.result)
        except Exception as e:
            ip = get_ipython()
            if ip is None:
                self.log.warn("Exception in interact callback: %s", e, exc_info=True)
            else:
                ip.showtraceback()
        finally:
            if self.manual:
                self.manual_button.disabled = False

    # Find abbreviations 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:38,代码来源:interaction.py

示例13: _add_dim

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def _add_dim(self, button):
        i = len(self.controller.children) - 1
        encoding = _get_encodings()[i]
        shelf = self._create_shelf(i=i)
        kids = self.controller.children
        teens = list(kids)[:-1] + [shelf] + [list(kids)[-1]]
        self.controller.children = teens

        # clear_output()
        # display(self.controller)
        self.settings["encodings"] += [{"encoding": encoding}]
        self.plot(self.settings) 
开发者ID:altair-viz,项目名称:altair_widgets,代码行数:14,代码来源:widget.py

示例14: clear_output

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def clear_output():
    def clear():
        return
    try:
        from IPython.display import clear_output as clear
    except ImportError as e:
        pass
    import os
    def cls():
        os.system('cls' if os.name == 'nt' else 'clear')

    clear()
    cls() 
开发者ID:thuml,项目名称:Separate_to_Adapt,代码行数:15,代码来源:utilities.py

示例15: __init__

# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import clear_output [as 别名]
def __init__(self, log_dir, clear=False):
        if clear:
            os.system('rm %s -r'%log_dir)
        tl.files.exists_or_mkdir(log_dir)
        self.writer = tf.summary.FileWriter(log_dir)
        self.step = 0
        self.log_dir = log_dir 
开发者ID:thuml,项目名称:Separate_to_Adapt,代码行数:9,代码来源:utilities.py


注:本文中的IPython.display.clear_output方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。