当前位置: 首页 > 工具软件 > clear > 使用案例 >

python 怎么样才有output_Python display.clear_output方法代码示例

黄聪
2023-12-01

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

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

示例1: get_display_progress_fn

​点赞 6

# 需要导入模块: 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,

示例2: plot_durations

​点赞 6

# 需要导入模块: 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,

示例3: __init__

​点赞 6

# 需要导入模块: 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,

示例4: interactive_output

​点赞 6

# 需要导入模块: 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,

示例5: plot

​点赞 6

# 需要导入模块: 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,

示例6: UpdateFromPIL

​点赞 5

# 需要导入模块: 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,

示例7: _update_trait

​点赞 5

# 需要导入模块: 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,

示例8: plot_live

​点赞 5

# 需要导入模块: 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,

示例9: update_plot

​点赞 5

# 需要导入模块: 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,

示例10: clear_output

​点赞 5

# 需要导入模块: 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,

示例11: capture

​点赞 5

# 需要导入模块: 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,

示例12: update

​点赞 5

# 需要导入模块: 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,

示例13: _add_dim

​点赞 5

# 需要导入模块: 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,

示例14: clear_output

​点赞 5

# 需要导入模块: 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,

示例15: __init__

​点赞 5

# 需要导入模块: 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,

示例16: init_display

​点赞 5

# 需要导入模块: from IPython import display [as 别名]

# 或者: from IPython.display import clear_output [as 别名]

def init_display(self):

# clear_output()

self.wResults.visible = False

self.wSearchButton.visible = True

开发者ID:sys-bio,项目名称:tellurium,代码行数:6,

示例17: try_clear

​点赞 5

# 需要导入模块: from IPython import display [as 别名]

# 或者: from IPython.display import clear_output [as 别名]

def try_clear():

if IS_NOTEBOOK:

display.clear_output()

else:

print()

开发者ID:keras-team,项目名称:keras-tuner,代码行数:7,

示例18: on_destroy_all_windows

​点赞 5

# 需要导入模块: from IPython import display [as 别名]

# 或者: from IPython.display import clear_output [as 别名]

def on_destroy_all_windows(self):

pass

#clear_output()

开发者ID:iperov,项目名称:DeepFaceLab,代码行数:5,

示例19: on_create_window

​点赞 5

# 需要导入模块: from IPython import display [as 别名]

# 或者: from IPython.display import clear_output [as 别名]

def on_create_window (self, wnd_name):

pass

#clear_output()

开发者ID:iperov,项目名称:DeepFaceLab,代码行数:5,

示例20: show_ui_ct

​点赞 5

# 需要导入模块: from IPython import display [as 别名]

# 或者: from IPython.display import clear_output [as 别名]

def show_ui_ct():

print('正在初始化界面元素,请稍后...')

from abupy import ABuStrUtil

go_on = True

try:

if ABuStrUtil.str_is_cn(str(ABuStrUtil.__file__)):

# 检测到运行环境路径中含有中文,严重错误,将出错,使用中文警告

msg = u'严重错误!当前运行环境下有中文路径,abu将无法正常运行!请不要使用中文路径名称, 当前环境为{}'.format(

ABuStrUtil.to_unicode(str(ABuStrUtil.__file__)))

import logging

logging.info(msg)

go_on = False

except:

# 如果是其它编码的字符路径会进到这里

import logging

msg = 'error!non English characters in the current running environment,abu will not work properly!'

logging.info(msg)

go_on = False

yield go_on

if go_on:

from IPython.display import clear_output

clear_output()

# import time

# 这里sleep(0.3)防止有些版本clear_output把下面要展示的清除了,也不能使用clear_output的wait参数,有些浏览器卡死

# time.sleep(0.3)

开发者ID:bbfamily,项目名称:abu,代码行数:29,

示例21: plot_test_acc

​点赞 5

# 需要导入模块: from IPython import display [as 别名]

# 或者: from IPython.display import clear_output [as 别名]

def plot_test_acc(plot_handles):

plt.legend(handles=plot_handles, loc="center right")

plt.xlabel("Iterations")

plt.ylabel("Test Accuracy")

plt.ylim(0,1)

display.display(plt.gcf())

display.clear_output(wait=True)

开发者ID:xialeiliu,项目名称:RotateNetworks,代码行数:9,

示例22: __init__

​点赞 4

# 需要导入模块: from IPython import display [as 别名]

# 或者: from IPython.display import clear_output [as 别名]

def __init__(self, __interact_f, __options={}, **kwargs):

VBox.__init__(self, _dom_classes=['widget-interact'])

self.result = None

self.args = []

self.kwargs = {}

self.f = f = __interact_f

self.clear_output = kwargs.pop('clear_output', True)

self.manual = __options.get("manual", False)

self.manual_name = __options.get("manual_name", "Run Interact")

self.auto_display = __options.get("auto_display", False)

new_kwargs = self.find_abbreviations(kwargs)

# Before we proceed, let's make sure that the user has passed a set of args+kwargs

# that will lead to a valid call of the function. This protects against unspecified

# and doubly-specified arguments.

try:

check_argspec(f)

except TypeError:

# if we can't inspect, we can't validate

pass

else:

getcallargs(f, **{n:v for n,v,_ in new_kwargs})

# Now build the widgets from the abbreviations.

self.kwargs_widgets = self.widgets_from_abbreviations(new_kwargs)

# This has to be done as an assignment, not using self.children.append,

# so that traitlets notices the update. We skip any objects (such as fixed) that

# are not DOMWidgets.

c = [w for w in self.kwargs_widgets if isinstance(w, DOMWidget)]

# If we are only to run the function on demand, add a button to request this.

if self.manual:

self.manual_button = Button(description=self.manual_name)

c.append(self.manual_button)

self.out = Output()

c.append(self.out)

self.children = c

# Wire up the widgets

# If we are doing manual running, the callback is only triggered by the button

# Otherwise, it is triggered for every trait change received

# On-demand running also suppresses running the function with the initial parameters

if self.manual:

self.manual_button.on_click(self.update)

# Also register input handlers on text areas, so the user can hit return to

# invoke execution.

for w in self.kwargs_widgets:

if isinstance(w, Text):

w.on_submit(self.update)

else:

for widget in self.kwargs_widgets:

widget.observe(self.update, names='value')

self.on_displayed(self.update)

# Callback function

开发者ID:luckystarufo,项目名称:pySINDy,代码行数:61,

示例23: update_progress

​点赞 4

# 需要导入模块: from IPython import display [as 别名]

# 或者: from IPython.display import clear_output [as 别名]

def update_progress(progress, bar_length=20):

"""Simple text-based progress bar for Jupyter notebooks.

Note that clear_output, and hence this function wipes the entire cell output,

including previous output and widgets.

Usage:

import pyradi.ryutils as ryutils

import time

print('before')

#Replace this with a real computation

number_of_elements = 100

for i in range(number_of_elements):

time.sleep(0.1)

# progress must be a float between 0 and 1

ryutils.update_progress((i+1) / number_of_elements,bar_length=40)

print('after')

source:

https://mikulskibartosz.name/how-to-display-a-progress-bar-in-jupyter-notebook-47bd4c2944bf

https://ipython.org/ipython-doc/3/api/generated/IPython.display.html#IPython.display.clear_output

Wait to clear the output until new output is available to replace it.

"""

from IPython.display import clear_output

if isinstance(progress, int):

progress = float(progress)

if not isinstance(progress, float):

progress = 0

if progress < 0:

progress = 0

if progress >= 1:

progress = 1

block = int(round(bar_length * progress))

clear_output(wait = True)

text = "Progress: [{0}] {1:.1f}%".format( "#" * block + "-" * (bar_length - block), progress * 100)

print(text)

##############################################################################

##

开发者ID:NelisW,项目名称:pyradi,代码行数:45,

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

 类似资料: