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


Python display.SVG属性代码示例

本文整理汇总了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)) 
开发者ID:altair-viz,项目名称:altair_widgets,代码行数:22,代码来源:widget.py

示例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) 
开发者ID:jbn,项目名称:IPlantUML,代码行数:19,代码来源:__init__.py

示例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()) 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:19,代码来源:visualize.py

示例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 
开发者ID:apache,项目名称:incubator-tvm,代码行数:22,代码来源:tedd.py

示例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 
开发者ID:Prooffreader,项目名称:chorogrid,代码行数:23,代码来源:Chorogrid.py

示例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 
开发者ID:Prooffreader,项目名称:chorogrid,代码行数:18,代码来源:Chorogrid.py

示例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( ) ) ) 
开发者ID:edwin-de-jong,项目名称:incremental-sequence-learning,代码行数:36,代码来源:utils.py

示例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( ) ) ) 
开发者ID:edwin-de-jong,项目名称:incremental-sequence-learning,代码行数:39,代码来源:utils.py

示例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( ) ) ) 
开发者ID:edwin-de-jong,项目名称:incremental-sequence-learning,代码行数:38,代码来源:utils.py

示例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) 
开发者ID:jbn,项目名称:IPlantUML,代码行数:15,代码来源:__init__.py

示例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 
开发者ID:samoturk,项目名称:mol2vec,代码行数:14,代码来源:helpers.py

示例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:', '')) 
开发者ID:samoturk,项目名称:mol2vec,代码行数:32,代码来源:helpers.py

示例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) 
开发者ID:samoturk,项目名称:mol2vec,代码行数:28,代码来源:helpers.py

示例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) 
开发者ID:holoviz,项目名称:holoviews,代码行数:15,代码来源:__init__.py

示例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)) 
开发者ID:jeanfeydy,项目名称:lddmm-ot,代码行数:37,代码来源:plotly.py


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