graphviz_output formats_输出格式

本文介绍了Graphviz系统支持的各种图形和数据格式,包括其在不同应用场景中的使用,以及如何通过命令行参数指定输出格式。同时讨论了图像文件的兼容性、插件需求以及id属性的生成规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Various graphic and data formats for end user, web, documents and other applications.

为最终用户、网络、文档和其他应用程序提供多种图形和数据格式。

FormatCommand-line parameterDescription
BMPbmpWindows Bitmap
CGImagecgimageApple Core Graphics
DOTcanon
dot
gv
xdot
xdot1.2
xdot1.4
Graphviz Language
EPSepsEncapsulated PostScript
EXRexrOpenEXR
FIGfigXfig
GD/GD2gd
gd2
LibGD
GIFgifGraphics Interchange Format
GTKgtkFormerly GTK+ / GIMP ToolKit
ICOicoWindows Icon
Imagemapimap
imap_np
ismap
cmap
cmapx
cmapx_np
Image Map: Server-side and client-side
JPEGjpg
jpeg
jpe
Joint Photographic Experts Group
JPEG 2000jp2
JSONjson
json0
dot_json
xdot_json
JavaScript Object Notation
PDFpdfPortable Document Format
PICpicBrian Kernighan’s Diagram Language
PICTpct
pict
Apple PICT
Plain Textplain plain-extSimple, line-based language
PNGpngPortable Network Graphics
POV-RaypovPersistence of Vision Raytracer (prototype)
PSpsAdobe PostScript
PS/PDFps2Adobe PostScript for Portable Document Format
PSDpsdPhotoshop
SGIsgiSilicon Graphics Image
SVGsvg
svgz
Scalable Vector Graphics
TGAtgaTruevision TARGA
TIFFtif
tiff
Tag Image File Format
TktkTcl/Tk
VMLvml
vmlz
Vector Markup Language.
VRMLvrmlVirtual Reality Modeling Language
WBMPwbmpWireless Bitmap
WebPwebpWebP
X11xlib
x11
X11 Window

The output format is specified with the -Tlang flag on the command line, where lang is one of the parameters listed above.

输出格式通过命令行上的 -Tlang 标志进行指定,其中 lang 是上述参数之一。

The formats actually available in a given Graphviz system depend on how the system was built and the presence of additional libraries.

实际在给定的 Graphviz 系统中可用的格式取决于系统的构建方式以及附加库的存在

To see what formats dot supports, run dot -T?.

要查看 dot 支持的格式,运行 dot -T?

See the description of the -T flag for additional information.

查看 -T 的描述标志了解更多信息。

Note that the internal coordinate system has the origin in the lower left corner.

请注意,内部坐标系统的原点位于左下角

Thus, positions in the canon, dot, xdot, plain, and plain-ext formats need to be interpreted in this manner.

因此,在 canondotxdotplainplain-ext 格式中的位置需要以这种方式进行解释

Image Formats

The image and shapefile attributes specify an image file to be included as part of the final diagram.

Not all image formats can be read.

imageshapefile属性指定、要作为最终图表一部分图像文件

并非所有图像格式都可以读取

In addition, even if read, not all image formats can necessarily be used in a given output format.

此外,即使可以读取也并非所有图像格式都必然能在给定的输出格式中使用。

The graph below shows what image formats can be used in which output formats, and the required plugins.

下面的图表显示了哪些图像格式可以用于哪些输出格式以及所需的插件

On the left are the supported image formats.

On the right are the supported output formats.

In the middle are the plugins: image loaders, renderers, drivers, arranged by plugin library.

This presents the most general case.

A given installation may not provide one of the plugins, in which case, that transformation is not possible.

左侧是支持的图像格式

右侧是支持的输出格式

中间是插件:图像加载器渲染器驱动程序,按插件库排列。

这表示最一般的情况

给定的安装可能不提供其中一个插件,在这种情况下,该转换无法实现

ID Output Note

In the formats: -Tcmap, -Tcmapx, -Tsvg, -Tvml,

the output generates id="node#" properties for nodes,

id="edge#" properties for edges,

and id="cluster#" properties for clusters,

with the # replaced by an internally assigned integer.

在以下格式中:-Tcmap,-Tcmapx,-Tsvg,-Tvml,

输出会为节点生成 id="node#" 属性

为边生成 id="edge#" 属性

为聚类生成 id="cluster#" 属性

其中 # 会被替换为 一个内部分配的整数

These strings can be provided instead by an externally provided id=xxx attribute on the object.

Normal \N \E \G substitutions are applied.

Externally provided id values are not used internally, and it is the user’s reponsibilty to ensure that they are sufficiently unique for their intended downstream use.

Note, in particular, that \E is not a unique id for multiedges.

这些字符串可以替代在对象上外部提供的id=xxx属性

正常的\N \E \G替换是适用的

外部提供的id值不会内部使用,而且确保它们对于预期的下游使用来说足够唯一用户的责任

请注意,特别是\E并不是多边的唯一id

### 创建和使用 Graphviz 表 #### 安装 Graphviz 对于不同操作系统的安装方法如下: - **Linux/macOS 用户** 对于基于 Ubuntu 或 Debian 的 Linux 发行版,可以使用命令 `sudo apt-get update` 和 `sudo apt-get install graphviz` 来完成软件的更新以及 Graphviz 的安装[^1]。macOS 用户如果已经安装了 Homebrew,则可以通过运行 `brew install graphviz` 命令来安装 Graphviz。 - **Windows 用户** 需要访问官方下载页面获取适合的操作系统版本(.exe),按照提示完成安装过程。建议在安装过程中选择将 Graphviz 添加至系统的 PATH 环境变量中以便后续可以直接调用 dot 工具。 #### 使用 Graphviz 绘制简单表 一旦成功安装好 Graphviz 后,在终端或命令提示符下就可以通过编写 DOT 文件定义形结构,并利用 dot 可执行文件渲染成像文件。下面是一个简单的例子说明如何创建一个 PNG 格式片表示两个节点之间的连接关系: ```plaintext digraph G { A -> B; } ``` 保存上述内容到名为 `example.dot` 的文本文件里,接着打开命令行工具输入以下指令生成可视化结果: ```bash dot -Tpng example.dot -o output.png ``` 这段命令会读取 `example.dot` 描述的信息并输出一张名称为 `output.png` 的位文件显示由A指向B的一条有向边。 #### 在 Python 中集成 Graphviz Python 社区提供了专门用于处理 Graphviz 数据的对象模型——pygraphviz 库或者是更常用的 graphviz python 包。后者允许开发者直接从代码内部构建 DOT 脚本而不需要额外依赖外部程序去解析这些脚本。这里给出一段简短的例子展示怎样借助 graphviz 包快速生成相同效果的二元树形结构: ```python from graphviz import Digraph g = Digraph('G', filename='binary_tree.gv') g.attr(rankdir='TB') with g.subgraph(name='cluster_0') as c: c.attr(label='Binary Tree Example') c.node_attr.update(style='filled', color='lightblue2') c.edge('root', 'left_child') c.edge('root', 'right_child') g.view() ``` 此段代码将会自动生成 `.gv` 文件并通过默认查看器呈现出来一棵具有根节点及其左右子节点构成的小型二叉树。 #### 浏览器端应用实例 除了本地环境下的开发外,还有在线服务可以帮助用户更加便捷地编辑和预览 Graphviz 纸。例如提到过的 [Graphviz-D3-Renderer](https://gitcode.com/gh_mirrors/gr/graph-viz-d3-js)[^3] 就是在网页上实现交互式绘的一个优秀案例,它能够把用户的输入即时转化为美观大方的数据流供分享交流之用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值