本文整理汇总了Python中IPython.display.Javascript方法的典型用法代码示例。如果您正苦于以下问题:Python display.Javascript方法的具体用法?Python display.Javascript怎么用?Python display.Javascript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.display
的用法示例。
在下文中一共展示了display.Javascript方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_next_cells
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def run_next_cells(n):
if n=='all':
n = 'NaN'
elif n<1:
return
js_code = """
var num = {0};
var run = false;
var current = $(this)[0];
$.each(IPython.notebook.get_cells(), function (idx, cell) {{
if ((cell.output_area === current) && !run) {{
run = true;
}} else if ((cell.cell_type == 'code') && !(num < 1) && run) {{
cell.execute();
num = num - 1;
}}
}});
""".format(n)
display(Javascript(js_code))
示例2: autosave
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def autosave(self, arg_s):
"""Set the autosave interval in the notebook (in seconds).
The default value is 120, or two minutes.
``%autosave 0`` will disable autosave.
This magic only has an effect when called from the notebook interface.
It has no effect when called in a startup file.
"""
try:
interval = int(arg_s)
except ValueError:
raise UsageError("%%autosave requires an integer, got %r" % arg_s)
# javascript wants milliseconds
milliseconds = 1000 * interval
display(Javascript("IPython.notebook.set_autosave_interval(%i)" % milliseconds),
include=['application/javascript']
)
if interval:
print("Autosaving every %i seconds" % interval)
else:
print("Autosave disabled")
示例3: setJupyterCellText
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def setJupyterCellText(text: str):
""" the function replaces the text in the current jupyter cell with the given text """
from IPython.display import Javascript, display
text = text.replace("\n", "\\n").replace("'", "\\'")
js = """
var output_area = this;
// find my cell element
var cell_element = output_area.element.parents('.cell');
// which cell is it?
var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);
// get the cell object
var cell = Jupyter.notebook.get_cell(cell_idx);
cell.get_text();
cell.set_text('"""+text+"""');
console.log('"""+text+"""');
"""
display(Javascript(js))
示例4: inject
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def inject(self):
try:
from IPython.display import HTML, display, Javascript
except:
print("IPython is required to produce maps.")
return
display(HTML(Template('''
<div id="$map_id"/>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.css' rel='stylesheet' />
<style>body{margin:0;padding:0;}#$map_id{position:relative;top:0;bottom:0;width:100%;height:400px;}</style>
<style>
#$map_id .mapboxgl-ctrl-icon.screencap-icon .download-btn {background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB2ZXJzaW9uPSIxLjEi%0D%0AIGlkPSJhdHRyYWN0aW9uLTE1IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdp%0D%0AZHRoPSIxNXB4IiBoZWlnaHQ9IjE1cHgiIHZpZXdCb3g9IjAgMCAxNSAxNSI+CiAgPHBhdGggaWQ9%0D%0AInJlY3Q3MTQzIiBkPSJNNiwyQzUuNDQ2LDIsNS4yNDc4LDIuNTA0NSw1LDNMNC41LDRoLTJDMS42%0D%0ANjksNCwxLDQuNjY5LDEsNS41djVDMSwxMS4zMzEsMS42NjksMTIsMi41LDEyaDEwJiN4QTsmI3g5%0D%0AO2MwLjgzMSwwLDEuNS0wLjY2OSwxLjUtMS41di01QzE0LDQuNjY5LDEzLjMzMSw0LDEyLjUsNGgt%0D%0AMkwxMCwzQzkuNzUsMi41LDkuNTU0LDIsOSwySDZ6IE0yLjUsNUMyLjc3NjEsNSwzLDUuMjIzOSwz%0D%0ALDUuNSYjeEE7JiN4OTtTMi43NzYxLDYsMi41LDZTMiw1Ljc3NjEsMiw1LjVTMi4yMjM5LDUsMi41%0D%0ALDV6IE03LjUsNWMxLjY1NjksMCwzLDEuMzQzMSwzLDNzLTEuMzQzMSwzLTMsM3MtMy0xLjM0MzEt%0D%0AMy0zUzUuODQzMSw1LDcuNSw1eiYjeEE7JiN4OTsgTTcuNSw2LjVDNi42NzE2LDYuNSw2LDcuMTcx%0D%0ANiw2LDhsMCwwYzAsMC44Mjg0LDAuNjcxNiwxLjUsMS41LDEuNWwwLDBDOC4zMjg0LDkuNSw5LDgu%0D%0AODI4NCw5LDhsMCwwQzksNy4xNzE2LDguMzI4NCw2LjUsNy41LDYuNSYjeEE7JiN4OTtMNy41LDYu%0D%0ANXoiLz4KPC9zdmc+'); background-position: center; background-repeat: no-repeat; cursor: default; padding: 5px; }
#$map_id .mapboxgl-ctrl.mapboxgl-ctrl-group.ctrl-group-horizontal { height: 30px; }
#$map_id .mapboxgl-ctrl.mapboxgl-ctrl-group.ctrl-group-horizontal > button { min-width: 30px; width: auto; height: 30px; display: inline-block !important; box-sizing: none; border-top: none; border-left: 1px solid #ddd; border-right: 1px solid #ddd; vertical-align: top; }
#$map_id .mapboxgl-ctrl.mapboxgl-ctrl-group.ctrl-group-horizontal > button > a { color: #6e6e6e; text-decoration: none; font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif; }
#$map_id .mapboxgl-ctrl.mapboxgl-ctrl-group.ctrl-group-horizontal > button:first-child,
#$map_id .mapboxgl-ctrl.mapboxgl-ctrl-group.ctrl-group-horizontal > button:last-child { border: none; }
#$map_id .mapboxgl-ctrl.mapboxgl-ctrl-group.ctrl-group-horizontal > button:not(:first-child) { padding: 0 4px 0 4px; }
.mapboxgl-popup-content table tr { border: 1px solid #efefef; } .mapboxgl-popup-content table, td, tr { border: none; }
<style>
''').substitute({"map_id": self.map_id})))
display(Javascript(self.template))
示例5: auto
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def auto(self, enabled=True, clear=False, **kwargs):
"""
Method to enable or disable automatic capture, allowing you to
simultaneously set the instance parameters.
"""
self.namespace = self.get_namespace()
self.notebook_name = "{notebook}"
self._timestamp = tuple(time.localtime())
kernel = r'var kernel = IPython.notebook.kernel; '
nbname = r"var nbname = IPython.notebook.get_notebook_name(); "
nbcmd = (r"var name_cmd = '%s.notebook_name = \"' + nbname + '\"'; " % self.namespace)
cmd = (kernel + nbname + nbcmd + "kernel.execute(name_cmd); ")
display(Javascript(cmd))
time.sleep(0.5)
self._auto=enabled
self.param.set_param(**kwargs)
tstamp = time.strftime(" [%Y-%m-%d %H:%M:%S]", self._timestamp)
# When clear == True, it clears the archive, in order to start a new auto capture in a clean archive
if clear:
FileArchive.clear(self)
print("Automatic capture is now %s.%s"
% ('enabled' if enabled else 'disabled',
tstamp if enabled else ''))
示例6: cell_javascript
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def cell_javascript(self):
"""
%%javascript - send contents of cell as JavaScript
This cell magic will execute the contents of the cell as
JavaScript in the browser.
Example:
%%javascript
element.html("Hello this is <b>bold</b>!")
"""
if self.code.strip():
jscode = Javascript(self.code)
self.kernel.Display(jscode)
self.evaluate = False
示例7: notebookSaveCheckpoint
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def notebookSaveCheckpoint():
"""Save a checkpoint of current notebook. Returns True on success."""
try:
from IPython.display import Javascript
from IPython.display import display
except ModuleNotFoundError:
import logging
logging.error("notebookSaveCheckpoint requires ipywidgets. It can be installed by running this command:\n\n pip_install('ipywidgets')\n")
return False
script = '''
require(["base/js/namespace"],function(Jupyter) {
Jupyter.notebook.save_checkpoint();
});
'''
display(Javascript(script))
return True
示例8: graph_display
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def graph_display(states, options={}):
stuff = prep_graph_display(states,options)
return Javascript("var tmp={}; window.nonint_next = window._graph_display(tmp.states, tmp.colormap, element[0], 0, tmp.options);".format(stuff))
示例9: noninteractive_next
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def noninteractive_next():
return Javascript("window.nonint_next()")
示例10: setup_graph_display
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def setup_graph_display():
with open(os.path.join(os.path.dirname(__file__), "display_graph.js"), 'r') as f:
JS_SETUP_STRING = f.read()
return Javascript(JS_SETUP_STRING)
示例11: to_dict
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def to_dict(self, index=0):
"""
Dict format for use in Javascript / Jason Chuang's display technology.
"""
index += 1
rep = {}
rep["index"] = index
rep["leaf"] = len(self.children) == 0
rep["depth"] = self.udepth
rep["scoreDistr"] = [0.0] * len(LabeledTree.SCORE_MAPPING)
# dirac distribution at correct label
if self.label is not None:
rep["scoreDistr"][self.label] = 1.0
mapping = LabeledTree.SCORE_MAPPING[:]
rep["rating"] = mapping[self.label] - min(mapping)
# if you are using this method for printing predictions
# from a model, the the dot product with the model's output
# distribution should be taken with this list:
rep["numChildren"] = len(self.children)
text = self.text if self.text != None else ""
seen_tokens = 0
witnessed_pixels = 0
for i, child in enumerate(self.children):
if i > 0:
text += " "
child_key = "child%d" % (i)
(rep[child_key], index) = child.to_dict(index)
text += rep[child_key]["text"]
seen_tokens += rep[child_key]["tokens"]
witnessed_pixels += rep[child_key]["pixels"]
rep["text"] = text
rep["tokens"] = 1 if (self.text != None and len(self.text) > 0) else seen_tokens
rep["pixels"] = witnessed_pixels + 3 if len(self.children) > 0 else text_size(self.text)
return (rep, index)
示例12: display
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def display(self):
from IPython.display import Javascript, display
display(Javascript("createTrees(["+self.to_json()+"])"))
display(Javascript("updateTrees()"))
示例13: inject_visualization_javascript
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def inject_visualization_javascript(tree_width=1200, tree_height=400, tree_node_radius=10):
"""
In an Ipython notebook, show SST trees using the same Javascript
code as used by Jason Chuang's visualisations.
"""
from .javascript import insert_sentiment_markup
insert_sentiment_markup(tree_width=tree_width, tree_height=tree_height, tree_node_radius=tree_node_radius)
示例14: to_jupyter
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def to_jupyter(
graph: BELGraph,
width: int = DEFAULT_WIDTH,
height: int = DEFAULT_HEIGHT,
color_map: Optional[Mapping[str, str]] = None,
):
"""Display a BEL graph inline in a Jupyter notebook.
To use successfully, make run as the last statement in a cell inside a Jupyter notebook.
:param graph: A BEL graph
:param width: The width of the visualization window to render
:param height: The height of the visualization window to render
:param color_map: A dictionary from PyBEL internal node functions to CSS color strings like #FFEE00. Defaults
to :data:`default_color_map`
:return: An IPython notebook Javascript object
:rtype: :class:`IPython.display.Javascript`
"""
from IPython.display import Javascript
return Javascript(to_jupyter_str(
graph,
width=width,
height=height,
color_map=color_map,
))
示例15: to_jupyter_str
# 需要导入模块: from IPython import display [as 别名]
# 或者: from IPython.display import Javascript [as 别名]
def to_jupyter_str(
graph: BELGraph,
width: int = DEFAULT_WIDTH,
height: int = DEFAULT_HEIGHT,
color_map: Optional[Mapping[str, str]] = None,
) -> str:
"""Return the string to be javascript-ified by the Jupyter notebook function :class:`IPython.display.Javascript`.
:param graph: A BEL graph
:param width: The width of the visualization window to render
:param height: The height of the visualization window to render
:param color_map: A dictionary from PyBEL internal node functions to CSS color strings like #FFEE00. Defaults
to :data:`default_color_map`
:return: The javascript string to turn into magic
"""
gjson = to_nodelink_jsons(graph)
chart_id = _generate_id()
#: Renders templates from pybel.io.jupyter.templates folder
render_template = build_template_renderer(__file__)
return render_template(
'pybel_jupyter.js',
graph=gjson,
chart=chart_id,
width=width,
height=height,
color_map=(color_map or DEFAULT_COLOR_MAP),
)