本文整理匯總了Python中IPython.display.SVG屬性的典型用法代碼示例。如果您正苦於以下問題:Python display.SVG屬性的具體用法?Python display.SVG怎麽用?Python display.SVG使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類IPython.display
的用法示例。
在下文中一共展示了display.SVG屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: plot
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [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))
示例2: plantuml_exec
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def plantuml_exec(*file_names, **kwargs):
"""
Given a list of UML documents, generate corresponding SVG diagrams.
:param file_names: the filenames of the documents for parsing by PlantUML.
:param kwargs: optionally `plantuml_path`, indicating where the PlantUML
jar file resides.
:return: the path to the generated SVG UML diagram.
"""
plantuml_path = kwargs.get('plantuml_path', PLANTUMLPATH)
cmd = ["java",
"-splash:no",
"-jar", plantuml_path,
"-tsvg"] + list(file_names)
return _exec_and_get_paths(cmd, file_names)
示例3: display_graph
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def display_graph(g, format='svg', include_asset_exists=False):
"""
Display a TermGraph interactively from within IPython.
"""
try:
import IPython.display as display
except ImportError:
raise NoIPython("IPython is not installed. Can't display graph.")
if format == 'svg':
display_cls = display.SVG
elif format in ("jpeg", "png"):
display_cls = partial(display.Image, format=format, embed=True)
out = BytesIO()
_render(g, out, format, include_asset_exists=include_asset_exists)
return display_cls(data=out.getvalue())
示例4: dump_graph
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def dump_graph(dot_string,
show_svg=True,
dot_file_path='',
output_dot_string=False):
"""Output dot_string in various formats."""
if dot_file_path:
try:
dot_file = open(dot_file_path, "w+")
dot_file.write(dot_string)
dot_file.close()
except IOError:
print('Cannot open file: ' + dot_file_path)
if show_svg:
from IPython.display import display
from IPython.display import SVG
src = Source(dot_string)
display(SVG(src.pipe(format='svg')))
if output_dot_string:
return dot_string
return None
示例5: done_and_overlay
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def done_and_overlay(self, other_chorogrid, show=True, save_filename=None):
"""Overlays a second chorogrid object on top of the root object."""
svgstring = ET.tostring(self.svg).decode('utf-8')
svgstring = svgstring.replace('</svg>', ''.join(self.additional_svg) + '</svg>')
svgstring = svgstring.replace(">", ">\n")
svgstring = svgstring.replace("</svg>", "")
svgstring_overlaid = ET.tostring(other_chorogrid.svg).decode('utf-8')
svgstring_overlaid = svgstring_overlaid.replace('</svg>',
''.join(other_chorogrid.additional_svg) + '</svg>')
svgstring_overlaid = svgstring_overlaid.replace(">", ">\n")
svgstring_overlaid = re.sub('<svg.+?>', '', svgstring_overlaid)
svgstring += svgstring_overlaid
if save_filename is not None:
if save_filename[-4:] != '.svg':
save_filename += '.svg'
with open(save_filename, 'w+', encoding='utf-8') as f:
f.write(svgstring)
if show:
display(SVG(svgstring))
# the .done() method
示例6: done
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def done(self, show=True, save_filename=None):
"""if show == True, displays the svg in IPython notebook. If save_filename
is specified, saves svg file"""
svgstring = ET.tostring(self.svg).decode('utf-8')
svgstring = svgstring.replace('</svg>', ''.join(self.additional_svg) + '</svg>')
svgstring = svgstring.replace(">", ">\n")
if save_filename is not None:
if save_filename[-4:] != '.svg':
save_filename += '.svg'
with open(save_filename, 'w+', encoding='utf-8') as f:
f.write(svgstring)
if show:
display(SVG(svgstring))
# the methods to draw square grids, map (traditional choropleth),
# hex grid, four-hex grid, multi-square grid
示例7: draw_strokes
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def draw_strokes( data, factor = 10, svg_filename = 'sample.svg' ):
min_x, max_x, min_y, max_y = get_bounds( data, factor )
dims = ( 50 + max_x - min_x, 50 + max_y - min_y )
dwg = svgwrite.Drawing( svg_filename, size = dims )
dwg.add( dwg.rect( insert = ( 0, 0 ), size = dims, fill = 'white' ) )
lift_pen = 1
abs_x = 25 - min_x
abs_y = 25 - min_y
p = "M%s, %s " % ( abs_x, abs_y )
command = "m"
for i in range( len( data ) ):
if ( lift_pen == 1 ):
command = "m"
elif ( command != "l" ):
command = "l"
else:
command = ""
x = float( data[ i, 0 ] )/factor
y = float( data[ i, 1 ] )/factor
lift_pen = data[ i, 2 ]
p += command+str( x )+", "+str( y )+" "
the_color = "black"
stroke_width = 1
dwg.add( dwg.path( p ).stroke( the_color, stroke_width ).fill( "none" ) )
dwg.save( )
display( SVG( dwg.tostring( ) ) )
示例8: draw_strokes_custom_color
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def draw_strokes_custom_color( data, factor = 10, svg_filename = 'test.svg', color_data = None, stroke_width = 1 ):
min_x, max_x, min_y, max_y = get_bounds( data, factor )
dims = ( 50 + max_x - min_x, 50 + max_y - min_y )
dwg = svgwrite.Drawing( svg_filename, size = dims )
dwg.add( dwg.rect( insert = ( 0, 0 ), size = dims, fill = 'white' ) )
lift_pen = 1
abs_x = 25 - min_x
abs_y = 25 - min_y
for i in range( len( data ) ):
x = float( data[ i, 0 ] )/factor
y = float( data[ i, 1 ] )/factor
prev_x = abs_x
prev_y = abs_y
abs_x += x
abs_y += y
if ( lift_pen == 1 ):
p = "M "+str( abs_x )+", "+str( abs_y )+" "
else:
p = "M +"+str( prev_x )+", "+str( prev_y )+" L "+str( abs_x )+", "+str( abs_y )+" "
lift_pen = data[ i, 2 ]
the_color = "black"
if ( color_data is not None ):
the_color = "rgb( "+str( int( color_data[ i, 0 ] ) )+", "+str( int( color_data[ i, 1 ] ) )+", "+str( int( color_data[ i, 2 ] ) )+" )"
dwg.add( dwg.path( p ).stroke( the_color, stroke_width ).fill( the_color ) )
dwg.save( )
display( SVG( dwg.tostring( ) ) )
示例9: draw_strokes_pdf
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def draw_strokes_pdf( data, param, factor = 10, svg_filename = 'sample_pdf.svg' ):
min_x, max_x, min_y, max_y = get_bounds( data, factor )
dims = ( 50 + max_x - min_x, 50 + max_y - min_y )
dwg = svgwrite.Drawing( svg_filename, size = dims )
dwg.add( dwg.rect( insert = ( 0, 0 ), size = dims, fill = 'white' ) )
abs_x = 25 - min_x
abs_y = 25 - min_y
num_mixture = len( param[ 0 ][ 0 ] )
for i in range( len( data ) ):
x = float( data[ i, 0 ] )/factor
y = float( data[ i, 1 ] )/factor
for k in range( num_mixture ):
pi = param[ i ][ 0 ][ k ]
if pi > 0.01: # optimisation, ignore pi's less than 1% chance
mu1 = param[ i ][ 1 ][ k ]
mu2 = param[ i ][ 2 ][ k ]
s1 = param[ i ][ 3 ][ k ]
s2 = param[ i ][ 4 ][ k ]
sigma = np.sqrt( s1*s2 )
dwg.add( dwg.circle( center = ( abs_x+mu1*factor, abs_y+mu2*factor ), r = int( sigma*factor ) ).fill( 'red', opacity = pi/( sigma*sigma*factor ) ) )
prev_x = abs_x
prev_y = abs_y
abs_x += x
abs_y += y
dwg.save( )
display( SVG( dwg.tostring( ) ) )
示例10: plantuml_web
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def plantuml_web(*file_names, **kwargs):
"""
Given a list of UML documents, generate corresponding SVG diagrams, using
PlantUML's web service via the plantweb module.
:param file_names: the filenames of the documents for parsing by PlantUML.
:return: the path to the generated SVG UML diagram.
"""
cmd = ["plantweb",
"--format",
"auto"] + list(file_names)
return _exec_and_get_paths(cmd, file_names)
示例11: _prepare_mol
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def _prepare_mol(mol, kekulize):
"""Prepare mol for SVG depiction (embed 2D coords)
"""
mc = Chem.Mol(mol.ToBinary())
if kekulize:
try:
Chem.Kekulize(mc)
except:
mc = Chem.Mol(mol.ToBinary())
if not mc.GetNumConformers():
rdDepictor.Compute2DCoords(mc)
return mc
示例12: mol_to_svg
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def mol_to_svg(mol, molSize=(300, 300), kekulize=True, drawer=None, font_size=0.8, **kwargs):
"""Generates a SVG from mol structure.
Inspired by: http://rdkit.blogspot.ch/2016/02/morgan-fingerprint-bit-statistics.html
Parameters
----------
mol : rdkit.Chem.rdchem.Mol
molSize : tuple
kekulize : bool
drawer : funct
Specify which drawing function to use (default: rdMolDraw2D.MolDraw2DSVG)
font_size : float
Atom font size
Returns
-------
IPython.display.SVG
"""
from IPython.display import SVG
mc = _prepare_mol(mol, kekulize)
mol_atoms = [a.GetIdx() for a in mc.GetAtoms()]
if drawer is None:
drawer = rdMolDraw2D.MolDraw2DSVG(*molSize)
drawer.SetFontSize(font_size)
drawer.DrawMolecule(mc, highlightAtomRadii={x: 0.5 for x in mol_atoms}, **kwargs)
drawer.FinishDrawing()
svg = drawer.GetDrawingText()
return SVG(svg.replace('svg:', ''))
示例13: depict_identifier
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def depict_identifier(mol, identifier, radius, useFeatures=False, **kwargs):
"""Depict an identifier in Morgan fingerprint.
Parameters
----------
mol : rdkit.Chem.rdchem.Mol
RDKit molecule
identifier : int or str
Feature identifier from Morgan fingerprint
radius : int
Radius of Morgan FP
useFeatures : bool
Use feature-based Morgan FP
Returns
-------
IPython.display.SVG
"""
identifier = int(identifier)
info = {}
AllChem.GetMorganFingerprint(mol, radius, bitInfo=info, useFeatures=useFeatures)
if identifier in info.keys():
atoms, radii = zip(*info[identifier])
return depict_atoms(mol, atoms, radii, **kwargs)
else:
return mol_to_svg(mol, **kwargs)
示例14: setUp
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def setUp(self):
super(IPTestCase, self).setUp()
try:
import IPython
from IPython.display import HTML, SVG
self.ip = IPython.InteractiveShell()
if self.ip is None:
raise TypeError()
except Exception:
raise SkipTest("IPython could not be started")
self.addTypeEqualityFunc(HTML, self.skip_comparison)
self.addTypeEqualityFunc(SVG, self.skip_comparison)
示例15: ishow
# 需要導入模塊: from IPython import display [as 別名]
# 或者: from IPython.display import SVG [as 別名]
def ishow(cls, figure_or_data, format='png', width=None, height=None,
scale=None):
"""Display a static image of the plot described by `figure_or_data`
in an IPython Notebook.
positional arguments:
- figure_or_data: The figure dict-like or data list-like object that
describes a plotly figure.
Same argument used in `py.plot`, `py.iplot`,
see https://plot.ly/python for examples
- format: 'png', 'svg', 'jpeg', 'pdf'
- width: output width
- height: output height
- scale: Increase the resolution of the image by `scale` amount
Only valid for PNG and JPEG images.
example:
```
import plotly.plotly as py
fig = {'data': [{'x': [1, 2, 3], 'y': [3, 1, 5], 'type': 'bar'}]}
py.image.ishow(fig, 'png', scale=3)
"""
if format == 'pdf':
raise exceptions.PlotlyError(
"Aw, snap! "
"It's not currently possible to embed a pdf into "
"an IPython notebook. You can save the pdf "
"with the `image.save_as` or you can "
"embed an png, jpeg, or svg.")
img = cls.get(figure_or_data, format, width, height, scale)
from IPython.display import display, Image, SVG
if format == 'svg':
display(SVG(img))
else:
display(Image(img))