graphviz能将图形约束到某个宽度吗?

2024-09-25 00:28:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python的graphviz来绘制日本汉字和它们之间的关系。我将输出导出为svg,并使用sfdp作为渲染引擎。 输出大致为正方形(3000x3000)。我想知道是否有任何方法可以指定一个约束,使输出更像一个垂直矩形(例如5000x1000)而不是一个正方形。 似乎大小参数主要作用于结果图像的比例,而不是节点本身的定位。但是我有很多不同的connexe组件,所以移动它们应该很容易。 我想做的是不可能的吗? 谢谢!你知道吗


Tags: 方法svg定位图像引擎参数节点关系
2条回答

sfdp,因为它使用spring模型,所以倾向于生成正方形图。但是,如果您使用dot,那么您就添加了rankrankdir这样的属性来根据自己的意愿来塑造图形。你知道吗

您可以参考Node, Edge and Graph Attributes来查看sfdp支持哪些属性。你知道吗

尝试使用^{}属性:

...

If ratio is numeric, it is taken as the desired aspect ratio. Then, if the actual aspect ratio is less than the desired ratio, the drawing height is scaled up to achieve the desired ratio; if the actual ratio is greater than that desired ratio, the drawing width is scaled up.

如果原始的图表是这样的:

enter image description here

添加graph [ratio="1.5"]属性将使其看起来像这样:

enter image description here

UPD:还要注意ratio属性是如何与size属性成对工作的,也许这种组合最适合您。详细的解释在比例文件的链接我已经张贴。你知道吗

相关问题 更多 >