graphviz#

graphviz 是一个流行的图形可视化库,PyGraphistry 可以与之接口。这使您能够利用 graphviz 强大的布局算法,以及可选的静态图片渲染器。它尤其以其“dot”布局算法而闻名,适用于节点和边少于10,000的层次和树形布局。

graphistry.plugins.graphviz.g_to_pgv(g, directed=True, strict=False, drop_unsanitary=False)#
Parameters:
  • g (Plottable)

  • directed (bool)

  • strict (布尔值)

  • drop_unsanitary (bool)

Return type:

graphistry.plugins.graphviz.g_with_pgv_layout(g, graph)#
Parameters:
Return type:

Plottable

graphistry.plugins.graphviz.layout_graphviz(self, prog='dot', args=None, directed=True, strict=False, graph_attr=None, node_attr=None, edge_attr=None, skip_styling=False, render_to_disk=False, path=None, format=None, drop_unsanitary=False)#

使用graphviz进行布局,例如层次树和有向无环图

需要安装pygraphviz Python绑定和graphviz本地库,请参阅https://pygraphviz.github.io/documentation/stable/install.html

查看 PROGS 以获取可用的布局算法

要将图像渲染到磁盘,请设置 render=True

Parameters:
  • self (Plottable) – 基础图

  • prog (graphistry.plugins_types.graphviz_types.Prog) – 布局算法 - “dot”, “neato”, …

  • args (可选[str]) – 传递给graphviz命令行以进行布局的额外参数

  • directed (bool) – 图是否为有向图(True,默认)或无向图(False)

  • strict (bool) – 图是否严格(True)或不严格(False,默认值)

  • graph_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.GraphAttr, Any]]) – Graphviz 图形属性,参见 https://graphviz.org/docs/graph/

  • node_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.NodeAttr, Any]]) – Graphviz 节点属性,参见 https://graphviz.org/docs/nodes/

  • edge_attr (Optional[Dict[graphistry.plugins_types.graphviz_types.EdgeAttr, Any]]) – Graphviz 边的属性,参见 https://graphviz.org/docs/edges/

  • skip_styling (bool) – 是否跳过应用默认样式(False,默认)或不跳过(True)

  • render_to_disk (bool) – 是否将图形渲染到磁盘(False,默认)或不渲染(True)

  • path (可选[str]) – 当 render_to_disk=True 时,保存渲染图像的路径

  • format (Optional[graphistry.plugins_types.graphviz_types.Format]) – 当render_to_disk=True时,渲染图像的格式

  • drop_unsanitary (bool) – 是否删除不卫生的属性(False,默认)或不删除(True),建议用于敏感设置

Returns:

应用了布局和样式设置的图表,设置x/y

Return type:

Plottable

Example: Dot layout for rigid hierarchical layout of trees and directed acyclic graphs
import graphistry
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz('dot').plot()

示例:用于小图有机布局的Neato布局

import graphistry
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz('neato').plot()

示例:在图形级别设置graphviz属性

import graphistry
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz(
    prog='dot',
    graph_attr={
        'ratio': 10
    }
).plot()

示例:将渲染的图像保存为png格式到磁盘

import graphistry
edges = pd.DataFrame({'s': ['a','b','c','d'], 'd': ['b','c','d','e']})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz(
    'dot',
    render_to_disk=True,
    path='graph.png',
    format='png'
)

示例:将渲染的图像保存为png格式,并传递渲染样式

import graphistry
edges = pd.DataFrame({
    's': ['a','b','c','d'],
    'd': ['b','c','d','e'],
    'color': ['red', None, None, 'yellow']
})
nodes = pd.DataFrame({
    'n': ['a','b','c','d','e'],
    'shape': ['circle', 'square', None, 'square', 'circle']
})
g = graphistry.edges(edges, 's', 'd')
g.layout_graphviz(
    'dot',
    render_to_disk=True,
    path='graph.png',
    format='png'
)
graphistry.plugins.graphviz.layout_graphviz_core(g, prog='dot', args=None, directed=True, strict=False, graph_attr=None, node_attr=None, edge_attr=None, drop_unsanitary=False)#
Parameters:
  • g (Plottable)

  • prog (Literal['acyclic', 'ccomps', 'circo', 'dot', 'fdp', 'gc', 'gvcolor', 'gvpr', 'neato', 'nop', 'osage', 'patchwork', 'sccmap', 'sfdp', 'tred', 'twopi', 'unflatten'])

  • args (str | None)

  • directed (bool)

  • strict (布尔值)

  • graph_attr (Dict[Literal['_background', 'bb', 'beautify', 'bgcolor', 'center', 'charset', 'class', 'clusterrank', 'colorscheme', 'comment', 'compound', 'concentrate', 'Damping', 'defaultdist', 'dim', 'dimen', 'diredgeconstraints', 'dpi', 'epsilon', 'esep', 'fontcolor', 'fontname', 'fontnames', 'fontpath', 'fontsize', 'forcelabels', 'gradientangle', 'href', 'id', 'imagepath', 'inputscale', 'K', 'label', 'label_scheme', 'labeljust', 'labelloc', 'landscape', 'layerlistsep', 'layers', 'layerselect', 'layersep', 'layout', 'levels', 'levelsgap', 'lheight', 'linelength', 'lp', 'lwidth', 'margin', 'maxiter', 'mclimit', 'mindist', 'mode', 'model', 'newrank', 'nodesep', 'nojustify', 'normalize', 'notranslate', 'nslimit', 'nslimit1', 'oneblock', 'ordering', 'orientation', 'outputorder', 'overlap', 'overlap_scaling', 'overlap_shrink', 'pack', 'packmode', 'pad', 'page', 'pagedir', 'quadtree', 'quantum', 'rankdir', 'ranksep', 'ratio', 'remincross', 'repulsiveforce', 'resolution', 'root', 'rotate', 'rotation', 'scale', 'searchsize', 'sep', 'showboxes', 'size', 'smoothing', 'sortv', 'splines', 'start', 'style', 'stylesheet', 'target', 'TBbalance', 'tooltip', 'truecolor', 'URL', 'viewport', 'voro_margin', 'xdotversion'], ~typing.Any] | None)

  • node_attr (Dict[Literal['area', 'class', 'color', 'colorscheme', 'comment', 'distortion', 'fillcolor', 'fixedsize', 'fontcolor', 'fontname', 'fontsize', 'gradientangle', 'group', 'height', 'href', 'id', 'image', 'imagepos', 'imagescale', 'label', 'labelloc', 'layer', 'margin', 'nojustify', 'ordering', 'orientation', 'penwidth', 'peripheries', 'pin', 'pos', 'rects', 'regular', 'root', 'samplepoints', 'shape', 'shapefile', 'showboxes', 'sides', 'skew', 'sortv', 'style', 'target', 'tooltip', 'URL', 'vertices', 'width', 'xlabel', 'xlp', 'z'], ~typing.Any] | None)

  • edge_attr (Dict[Literal['arrowhead', 'arrowsize', 'arrowtail', 'class', 'color', 'colorscheme', 'comment', 'constraint', 'decorate', 'dir', 'edgehref', 'edgetarget', 'edgetooltip', 'edgeURL', 'fillcolor', 'fontcolor', 'fontname', 'fontsize', 'head_lp', 'headclip', 'headhref', 'headlabel', 'headport', 'headtarget', 'headtooltip', 'headURL', 'href', 'id', 'label', 'labelangle', 'labeldistance', 'labelfloat', 'labelfontcolor', 'labelfontname', 'labelfontsize', 'labelhref', 'labeltarget', 'labeltooltip', 'labelURL', 'layer', 'len', 'lhead', 'lp', 'ltail', 'minlen', 'nojustify', 'penwidth', 'pos', 'samehead', 'sametail', 'showboxes', 'style', 'tail_lp', 'tailclip', 'tailhref', 'taillabel', 'tailport', 'tailtarget', 'tailtooltip', 'tailURL', 'target', 'tooltip', 'URL', 'weight', 'xlabel', 'xlp'], ~typing.Any] | None)

  • drop_unsanitary (bool)

Return type:

graphistry.plugins.graphviz.pgv_styling(g)#
Parameters:

g (Plottable)

Return type:

Plottable

常量

graphistry.plugins_types.graphviz_types.EdgeAttr

Literal 的别名 ['arrowhead', 'arrowsize', 'arrowtail', 'class', 'color', 'colorscheme', 'comment', 'constraint', 'decorate', 'dir', 'edgehref', 'edgetarget', 'edgetooltip', 'edgeURL', 'fillcolor', 'fontcolor', 'fontname', 'fontsize', 'head_lp', 'headclip', 'headhref', 'headlabel', 'headport', 'headtarget', 'headtooltip', 'headURL', 'href', 'id', 'label', 'labelangle', 'labeldistance', 'labelfloat', 'labelfontcolor', 'labelfontname', 'labelfontsize', 'labelhref', 'labeltarget', 'labeltooltip', 'labelURL', 'layer', 'len', 'lhead', 'lp', 'ltail', 'minlen', 'nojustify', 'penwidth', 'pos', 'samehead', 'sametail', 'showboxes', 'style', 'tail_lp', 'tailclip', 'tailhref', 'taillabel', 'tailport', 'tailtarget', 'tailtooltip', 'tailURL', 'target', 'tooltip', 'URL', 'weight', 'xlabel', 'xlp']

graphistry.plugins_types.graphviz_types.Format

Literal的别名 ['canon', 'cmap', 'cmapx', 'cmapx_np', 'dia', 'dot', 'fig', 'gd', 'gd2', 'gif', 'hpgl', 'imap', 'imap_np', 'ismap', 'jpe', 'jpeg', 'jpg', 'mif', 'mp', 'pcl', 'pdf', 'pic', 'plain', 'plain-ext', 'png', 'ps', 'ps2', 'svg', 'svgz', 'vml', 'vmlz', 'vrml', 'vtx', 'wbmp', 'xdot', 'xlib']

graphistry.plugins_types.graphviz_types.GraphAttr

Literal 的别名 ['_background', 'bb', 'beautify', 'bgcolor', 'center', 'charset', 'class', 'clusterrank', 'colorscheme', 'comment', 'compound', 'concentrate', 'Damping', 'defaultdist', 'dim', 'dimen', 'diredgeconstraints', 'dpi', 'epsilon', 'esep', 'fontcolor', 'fontname', 'fontnames', 'fontpath', 'fontsize', 'forcelabels', 'gradientangle', 'href', 'id', 'imagepath', 'inputscale', 'K', 'label', 'label_scheme', 'labeljust', 'labelloc', 'landscape', 'layerlistsep', 'layers', 'layerselect', 'layersep', 'layout', 'levels', 'levelsgap', 'lheight', 'linelength', 'lp', 'lwidth', 'margin', 'maxiter', 'mclimit', 'mindist', 'mode', 'model', 'newrank', 'nodesep', 'nojustify', 'normalize', 'notranslate', 'nslimit', 'nslimit1', 'oneblock', 'ordering', 'orientation', 'outputorder', 'overlap', 'overlap_scaling', 'overlap_shrink', 'pack', 'packmode', 'pad', 'page', 'pagedir', 'quadtree', 'quantum', 'rankdir', 'ranksep', 'ratio', 'remincross', 'repulsiveforce', 'resolution', 'root', 'rotate', 'rotation', 'scale', 'searchsize', 'sep', 'showboxes', 'size', 'smoothing', 'sortv', 'splines', 'start', 'style', 'stylesheet', 'target', 'TBbalance', 'tooltip', 'truecolor', 'URL', 'viewport', 'voro_margin', 'xdotversion']

graphistry.plugins_types.graphviz_types.NodeAttr

Literal的别名['area', 'class', 'color', 'colorscheme', 'comment', 'distortion', 'fillcolor', 'fixedsize', 'fontcolor', 'fontname', 'fontsize', 'gradientangle', 'group', 'height', 'href', 'id', 'image', 'imagepos', 'imagescale', 'label', 'labelloc', 'layer', 'margin', 'nojustify', 'ordering', 'orientation', 'penwidth', 'peripheries', 'pin', 'pos', 'rects', 'regular', 'root', 'samplepoints', 'shape', 'shapefile', 'showboxes', 'sides', 'skew', 'sortv', 'style', 'target', 'tooltip', 'URL', 'vertices', 'width', 'xlabel', 'xlp', 'z']

graphistry.plugins_types.graphviz_types.Prog

Literal的别名 ['acyclic', 'ccomps', 'circo', 'dot', 'fdp', 'gc', 'gvcolor', 'gvpr', 'neato', 'nop', 'osage', 'patchwork', 'sccmap', 'sfdp', 'tred', 'twopi', 'unflatten']

graphistry.plugins_types.graphviz_types.EDGE_ATTRS typing.List[graphistry.plugins_types.graphviz_types.EdgeAttr]#

内置可变序列。

如果没有给出参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。

graphistry.plugins_types.graphviz_types.FORMATS typing.List[graphistry.plugins_types.graphviz_types.Format]#

内置可变序列。

如果没有给出参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。

graphistry.plugins_types.graphviz_types.GRAPH_ATTRS typing.List[graphistry.plugins_types.graphviz_types.GraphAttr]#

内置可变序列。

如果没有给出参数,构造函数将创建一个新的空列表。 如果指定了参数,则参数必须是一个可迭代对象。

graphistry.plugins_types.graphviz_types.NODE_ATTRS typing.List[graphistry.plugins_types.graphviz_types.NodeAttr]#

内置可变序列。

如果没有给出参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。

graphistry.plugins_types.graphviz_types.PROGS typing.List[graphistry.plugins_types.graphviz_types.Prog]#

内置可变序列。

如果没有给出参数,构造函数将创建一个新的空列表。 如果指定了参数,则它必须是一个可迭代对象。