我试图在使用Graphviz进行渲染的Python模块diagrams中创建一个包含两个 node (在这里可视化为用户)的水平集群.

但实现这一点的唯一方法是在 node 之间添加边.

水平,但在 node 之间显示边缘

from diagrams import Cluster, Diagram
from diagrams.onprem.client import User

with Diagram("sample", show=False) as diag:
    with Cluster("sample horizontal cluster with edge"):
        node1 = User("Some Node")
        node2 = User("Some other Node")
        node1 >> node2

这将产生:

enter image description here

没有边,但垂直

我试着在没有连接的情况下node1 >> node2:

    with Cluster("sample horizontal cluster with edge", direction="LR"):
        node1 = User("Some Node")
        node2 = User("Some other Node")

Then it renders vertically, which I don't want: enter image description here

我不想看到那条边,但要让 node 水平排列.

我怎样才能做到这一点呢?

推荐答案

查看这个example from Edges guide并使用GraphViz的style atrribute支持的style="invis"连接invisible edge:

from diagrams import Cluster, Diagram, Edge
from diagrams.onprem.client import User

with Diagram("invisible_edge", show=False) as diag:
    with Cluster("sample horizontal cluster with invisible edge"):
        node1 = User("Some Node")
        node2 = User("Some other Node")
        node1 - Edge(style='invis') - node2

Renders using GraphViz to: nodes connected using invisible edge

Python相关问答推荐

如何使用stride_tricks.as_strided逆转NumPy数组

如何自动抓取以下CSV

如何让剧作家等待Python中出现特定cookie(然后返回它)?

计算组中唯一值的数量

梯度下降:简化要素集的运行时间比原始要素集长

实现自定义QWidgets作为QTimeEdit的弹出窗口

迭代嵌套字典的值

无法在Docker内部运行Python的Matlab SDK模块,但本地没有问题

在Python中,从给定范围内的数组中提取索引组列表的更有效方法

如何使用SentenceTransformers创建矢量嵌入?

Django admin Csrf令牌未设置

基于形状而非距离的两个numpy数组相似性

Geopandas未返回正确的缓冲区(单位:米)

将标签移动到matplotlib饼图中楔形块的开始处

如何使用OpenGL使球体遵循Python中的八样路径?

为什么在FastAPI中创建与数据库的连接时需要使用生成器?

Django Table—如果项目是唯一的,则单行

如何使用matplotlib查看并列直方图

Polars表达式无法访问中间列创建表达式

利用SCIPY沿第一轴对数组进行内插