如何将Graphviz流程图的图例定位在图表左下角?
把Graphviz图例移到左下角的方法
要将图例子图放到图表左下角,你可以通过强制rank层级和不可见辅助边来实现,以下是修改后的完整代码:
# Graph graph [ overlap = true fontsize = 10 ] # Define styles for Datasets and Analyses node [fontname = 'Calibri Light', fontcolor = white, style = filled] # Datasets (boxes) node [shape = box, fillcolor = firebrick3] # Set dataset style A B # Analyses (circles) node [shape = circle, fixedsize = true, width = .9, fillcolor = steelblue3] C D # Edges {A B}->C A->D # Subgraph for legend subgraph cluster_legend { graph [ label = 'Legend' labelloc = 't' labeljust= 'l' fontname = 'Calibri Light' color = lightgrey rank = sink # 强制图例子图排在整个图表的最底部 margin = 10 # 调整子图边距,避免和主图节点太近 ] # Global node style node [fontsize = 9] # Legend entry for Analysis node [shape = circle, fixedsize = true, fillcolor = steelblue3, width = .5, height = .3] legend_analysis [label = 'Analysis'] # Legend entry for Data node [shape = box, fillcolor = firebrick3, width = .5, height = .5] legend_data [label = 'Data'] # Make legend items horizontal {rank = same; legend_data; legend_analysis} } # 添加不可见边,让图例和左下角的B节点对齐,确保靠左 B -> legend_data [style = invis] }
关键修改点说明:
rank = sink:将图例子图设置为整个图表的最低层级,确保它位于底部区域- 不可见边
B -> legend_data [style = invis]:强制图例子图和左下角的B节点在水平方向对齐,避免图例偏移到底部中间 margin = 10:调整图例子图的内边距,优化和主图节点的视觉间距
如果你的图表左下角节点不是B,只需要把不可见边的起点换成对应节点即可。
内容的提问来源于stack exchange,提问作者mat
相关产品推荐
相关产品推荐

