admin管理员组文章数量:1406918
The code below successfully produces the body of the diagram that I am trying to create.
Help needed: how can I add the title boxes "Codes", "Secondary Codes" and "Themes" which sit at the top of each section?
Things I've tried:
Adding
label
to the nodes: but this places the label above the individual lines and not at the top of the sectionCreating new nodes just for the titles but it all falls apart when I try to connect them with the edge.
from graphviz import Digraph
# rankdir: sets direction of graph layout /
dot = Digraph(graph_attr={'rankdir':'LR'})
# Themes
# Set attributes to force orthogonal lines
dot.attr(splines='ortho')
# Set the gap between the nodes
dot.attr(nodesep='0.1')
dot.node('T1', 'Drivers', shape='ellipse', style='filled', color='darkred', fontcolor='white')
dot.node('T2', 'Challenges &\nInitial Concerns', shape='ellipse', style='filled', color='darkorange', fontcolor='white')
dot.node('T3', 'Benefits', shape='ellipse', style='filled', color='darkgreen', fontcolor='white')
# Add secondary codes and link to themes v2
dot.node('Financial Challenges', shape='box', style='rounded', pos='0,1!', width='2', height='0.5', fixedsize='true')
dot.edge('Financial Challenges', 'T1', arrowhead='none')
dot.node('Commercial Challenges', shape='box', style='rounded', pos='1,1!', width='2', height='0.5', fixedsize='true')
dot.edge('Commercial Challenges', 'T1', arrowhead='none')
dot.node('Lack of Human Capital', shape='box', style='rounded', pos='3,1!', width='2', height='0.5', fixedsize='true')
dot.edge('Lack of Human Capital', 'T1', arrowhead='none')
dot.node('Open Innovation', shape='box', style='rounded', pos='0,1!', width='2', height='0.5', fixedsize='true')
dot.edge('Open Innovation', 'T2', arrowhead='none')
dot.node('Reputational Damage', shape='box', style='rounded', pos='1,1!', width='2', height='0.5', fixedsize='true')
dot.edge('Reputational Damage', 'T2', arrowhead='none')
dot.node('Structure Contrast', shape='box', style='rounded', pos='2,1!', width='2', height='0.5', fixedsize='true')
dot.edge('Structure Contrast', 'T2', arrowhead='none')
dot.node('Human Capital', shape='box', style='rounded', pos='0,1!', width='2', height='0.5', fixedsize='true')
dot.edge('Human Capital', 'T3', arrowhead='none')
dot.node('Social Capital', shape='box', style='rounded', pos='1,1!', width='2', height='0.5', fixedsize='true')
dot.edge('Social Capital', 'T3', arrowhead='none')
dot.node('Credibility & \n Investor Trust', shape='box', style='rounded', pos='2', width='2', height='0.6', fixedsize='true')
dot.edge('Credibility & \n Investor Trust', 'T3', arrowhead='none')
# Create dictionary of the 'codes'
# Key = string; Val = secondary code to link to
# Use \l to left align the content on line break
codes = {
'• Lack of resources \l• Lack of investment funding \l': 'Financial Challenges',
'• Lack of investor trust \l• Brand association \l': 'Commercial Challenges',
'• Lack of sector insights \l• Mentoring \l': 'Lack of Human Capital',
'• Intellectual property \l• Idea sharing \l• Power dynamic \l': 'Open Innovation',
'• Public perception of oil and gas company \l': 'Reputational Damage',
'• Pace of business \l• Decision-making process \l': 'Structure Contrast',
'• Specialised knowledge and expertise through mentoring \l• Technical peer review with experts \l': 'Human Capital',
'• Access to global networks \l• Knowledge spillover between cohort members \l': 'Social Capital',
'• Brand association \l': 'Credibility & \n Investor Trust'
}
# Add codes and link to the secondary_codes
for code_string, secondary_code in codes.items():
dot.node(code_string, shape='box', width='4.5', height='1', fixedsize='true')
dot.edge(code_string, secondary_code, arrowhead='none')
# Scrappy way to set the colors on the secondary codes
dot.node('Financial Challenges', color='red')
dot.node('Commercial Challenges', color='red')
dot.node('Lack of Human Capital', color='red')
dot.node('Open Innovation', color='orange')
dot.node('Reputational Damage', color='orange')
dot.node('Structure Contrast', color='orange')
dot.node('Human Capital', color='green')
dot.node('Social Capital', color='green')
dot.node('Credibility & \n Investor Trust', color='green')
# Render
dot.render('coding_tree', format='png', cleanup=True)
本文标签: graphvizHow to have title boxes for each sectionStack Overflow
版权声明:本文标题:graphviz - How to have title boxes for each section? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744331471a2600984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论