本文整理汇总了Python中IPython.display方法的典型用法代码示例。如果您正苦于以下问题:Python IPython.display方法的具体用法?Python IPython.display怎么用?Python IPython.display使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython
的用法示例。
在下文中一共展示了IPython.display方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: display_images
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def display_images(images, titles=None, cols=4, cmap=None, norm=None,
interpolation=None):
"""Display the given set of images, optionally with titles.
images: list or array of image tensors in HWC format.
titles: optional. A list of titles to display with each image.
cols: number of images per row
cmap: Optional. Color map to use. For example, "Blues".
norm: Optional. A Normalize instance to map values to colors.
interpolation: Optional. Image interpolation to use for display.
"""
titles = titles if titles is not None else [""] * len(images)
rows = len(images) // cols + 1
plt.figure(figsize=(14, 14 * rows // cols))
i = 1
for image, title in zip(images, titles):
plt.subplot(rows, cols, i)
plt.title(title, fontsize=9)
plt.axis('off')
plt.imshow(image.astype(np.uint8), cmap=cmap,
norm=norm, interpolation=interpolation)
i += 1
plt.show()
示例2: display_logon_data
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def display_logon_data(
logon_event: pd.DataFrame, alert: SecurityAlert = None, os_family: str = None
):
"""
Display logon data for one or more events as HTML table.
Parameters
----------
logon_event : pd.DataFrame
Dataframe containing one or more logon events
alert : SecurityAlert, optional
obtain os_family from the security alert
(the default is None)
os_family : str, optional
explicitly specify os_family (Linux or Windows)
(the default is None)
Notes
-----
Currently only Windows Logon events.
"""
display(format_logon(logon_event, alert, os_family))
示例3: display_alert
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def display_alert(
alert: Union[Mapping[str, Any], SecurityAlert], show_entities: bool = False
):
"""
Display a Security Alert.
Parameters
----------
alert : Union[Mapping[str, Any], SecurityAlert]
The alert to display as Mapping (e.g. pd.Series)
or SecurityAlert
show_entities : bool, optional
Whether to display entities (the default is False)
"""
output = format_alert(alert, show_entities)
if not isinstance(output, tuple):
output = [output]
for disp_obj in output:
display(disp_obj)
示例4: display_process_tree
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def display_process_tree(process_tree: pd.DataFrame):
"""
Display process tree data frame. (Deprecated).
Parameters
----------
process_tree : pd.DataFrame
Process tree DataFrame
The display module expects the columns NodeRole and Level to
be populated. NoteRole is one of: 'source', 'parent', 'child'
or 'sibling'. Level indicates the 'hop' distance from the 'source'
node.
"""
build_and_show_process_tree(process_tree)
示例5: post_execute
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def post_execute(self):
if self.isFirstPostExecute:
self.isFirstPostExecute = False
self.isFirstPreExecute = False
return 0
self.flag = False
self.asyncCapturer.Wait()
self.ioHandler.Poll()
self.ioHandler.EndCapture()
# Print for the notebook
out = self.ioHandler.GetStdout()
err = self.ioHandler.GetStderr()
if not transformers:
sys.stdout.write(out)
sys.stderr.write(err)
else:
for t in transformers:
(out, err, otype) = t(out, err)
if otype == 'html':
IPython.display.display(HTML(out))
IPython.display.display(HTML(err))
return 0
示例6: display_images
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def display_images(images, titles=None, cols=4, cmap=None, norm=None,
interpolation=None):
"""Display the given set of images, optionally with titles.
images: list or array of image tensors in HWC format.
titles: optional. A list of titles to display with each image.
cols: number of images per row
cmap: Optional. Color map to use. For example, "Blues".
norm: Optional. A Normalize instance to map values to colors.
interpolation: Optional. Image interporlation to use for display.
"""
titles = titles if titles is not None else [""] * len(images)
rows = len(images) // cols + 1
plt.figure(figsize=(14, 14 * rows // cols))
i = 1
for image, title in zip(images, titles):
plt.subplot(rows, cols, i)
plt.title(title, fontsize=9)
plt.axis('off')
plt.imshow(image.astype(np.uint8), cmap=cmap,
norm=norm, interpolation=interpolation)
i += 1
plt.show()
示例7: check_render_options
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def check_render_options(**options):
"""
Context manager that will assert that alt.renderers.options are equivalent
to the given options in the IPython.display.display call
"""
import IPython.display
def check_options(obj):
assert alt.renderers.options == options
_display = IPython.display.display
IPython.display.display = check_options
try:
yield
finally:
IPython.display.display = _display
示例8: register_json_formatter
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def register_json_formatter(cls: Type, to_dict_method_name: str = 'to_dict'):
"""
TODO
:param cls:
:param to_dict_method_name:
:return:
"""
if not hasattr(cls, to_dict_method_name) or not callable(getattr(cls, to_dict_method_name)):
raise ValueError(f'{cls} must define a {to_dict_method_name}() method')
try:
import IPython
import IPython.display
if IPython.get_ipython() is not None:
def obj_to_dict(obj):
return getattr(obj, to_dict_method_name)()
ipy_formatter = IPython.get_ipython().display_formatter.formatters['application/json']
ipy_formatter.for_type(cls, obj_to_dict)
except ImportError:
pass
示例9: render
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def render(obj, **kwargs):
info = process_object(obj)
if info:
display(HTML(info))
return
if render_anim is not None:
return render_anim(obj)
backend = Store.current_backend
renderer = Store.renderers[backend]
# Drop back to png if pdf selected, notebook PDF rendering is buggy
if renderer.fig == 'pdf':
renderer = renderer.instance(fig='png')
return renderer.components(obj, **kwargs)
示例10: image_display
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def image_display(element, max_frames, fmt):
"""
Used to render elements to an image format (svg or png) if requested
in the display formats.
"""
if fmt not in Store.display_formats:
return None
info = process_object(element)
if info:
display(HTML(info))
return
backend = Store.current_backend
if type(element) not in Store.registry[backend]:
return None
renderer = Store.renderers[backend]
plot = renderer.get_plot(element)
# Current renderer does not support the image format
if fmt not in renderer.param.objects('existing')['fig'].objects:
return None
data, info = renderer(plot, fmt=fmt)
return {info['mime_type']: data}, {}
示例11: wait_for_import
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def wait_for_import(self, count, timeout=300):
time_start = time.time()
while time.time() < time_start + timeout:
t = self.client.table(self.database, self.table)
self.imported_count = t.count - self.initial_count
if self.imported_count >= count:
break
self._display_progress(self.frame_size)
time.sleep(2)
# import finished
self.imported_at = datetime.datetime.utcnow().replace(microsecond=0)
# import timeout
if self.imported_count < count:
self.import_timeout = timeout
self._display_progress(self.frame_size)
# clear progress
if self.clear_progress and self.imported_count == count:
IPython.display.clear_output()
# public methods
示例12: display_images
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def display_images(images, titles=None, cols=4, cmap=None, norm=None,
interpolation=None):
"""Display the given set of images, optionally with titles.
images: list or array of image tensors in HWC format.
titles: optional. A list of titles to display with each image.
cols: number of images per row
cmap: Optional. Color map to use. For example, "Blues".
norm: Optional. A Normalize instance to map values to colors.
interpolation: Optional. Image interporlation to use for display.
"""
titles = titles if titles is not None else [""] * len(images)
rows = len(images) // cols + 1
plt.figure(figsize=(14, 14 * rows // cols))
i = 1
for image, title in zip(images, titles):
plt.subplot(rows, cols, i)
plt.title(title, fontsize=9)
plt.axis('off')
plot_area = image[:,:,0] if len(image.shape) == 3 else image
plt.imshow(plot_area.astype(np.uint8), cmap=cmap,
norm=norm, interpolation=interpolation)
i += 1
plt.show()
示例13: display_table
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def display_table(table):
"""Display values in a table format.
table: an iterable of rows, and each row is an iterable of values.
"""
html = ""
for row in table:
row_html = ""
for col in row:
row_html += "<td>{:40}</td>".format(str(col))
html += "<tr>" + row_html + "</tr>"
html = "<table>" + html + "</table>"
IPython.display.display(IPython.display.HTML(html))
示例14: format_alert
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def format_alert(
alert: Union[Mapping[str, Any], SecurityAlert], show_entities: bool = False
) -> Union[IPython.display.HTML, Tuple[IPython.display.HTML, pd.DataFrame]]:
"""
Get IPython displayable Security Alert.
Parameters
----------
alert : Union[Mapping[str, Any], SecurityAlert]
The alert to display as Mapping (e.g. pd.Series)
or SecurityAlert
show_entities : bool, optional
Whether to display entities (the default is False)
Returns
-------
Union[IPython.display.HTML, Tuple[IPython.display.HTML, pd.DataFrame]]
Single or tuple of displayable IPython objects
Raises
------
ValueError
If the alert object is in an unknown format
"""
if isinstance(alert, SecurityAlert):
return HTML(alert.to_html(show_entities=show_entities))
# Display subset of raw properties
if isinstance(alert, pd.Series):
entity = alert["CompromisedEntity"] if "CompromisedEntity" in alert else ""
title = f"""
<h3>Series Alert: '{alert["AlertDisplayName"]}'</h3>
<b>Alert_time:</b> {alert["StartTimeUtc"]},
<b>Compr_entity:</b> {entity},
<b>Alert_id:</b> {alert["SystemAlertId"]}
<br/>
"""
return HTML(title), pd.DataFrame(alert)
raise ValueError("Unrecognized alert object type " + str(type(alert)))
示例15: to_notebook
# 需要导入模块: import IPython [as 别名]
# 或者: from IPython import display [as 别名]
def to_notebook(self, transparent_bg=True, scale=(1, 1)):
# if not in_notebook():
# raise ValueError("Cannot find notebook.")
wimg = self._win2img(transparent_bg, scale)
writer = BSPNGWriter(writeToMemory=True)
result = serial_connect(wimg, writer, as_data=False).result
data = memoryview(result).tobytes()
from IPython.display import Image
return Image(data)