title: How to color a specific path in a graphviz dot file using python
body: <p>Hello I am iterating a dot file in python using <a href="https://pypi.org/project/pydot/" rel="nofollow noreferrer">pydot</a> package. I want to color all nodes and edges in a graph who are a parent of particular node unto the starting root. the images below describes the goal.</p>
  <p><strong>Actual Graph is following</strong></p>
  <p><a href="https://i.stack.imgur.com/wO09C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wO09C.png" alt="The actual graph" /></a></p>
  <p><strong>Required Output assuming given node is _ZL3WTFv</strong></p>
  <p><a href="https://i.stack.imgur.com/8XhBm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8XhBm.png" alt="Required goal" /></a></p>
  <p><strong>Python code is following</strong></p>
  <pre><code>import pydot
  import sys
  
  def Clean(inp):
      return inp.replace('&quot;{', '').replace('}&quot;', '')
  
  def GetNode(path):
      graph = pydot.graph_from_dot_file(path)
      graph = graph[0]
      nodesList = graph.get_nodes() 
      for e in nodesList:
          tempAttr = e.get_attributes()
          print('Checking', Clean(tempAttr['label']))
          if Clean(tempAttr['label']) == '_ZL3WTFv':
              #how to mark all nodes &amp; paths to the top level parents from here e.g. _ZL3WTFv          
              print('Node Found!')
              break
  
  if len(sys.argv) &gt; 1:
      GetNode(sys.argv[1])
  else:
      print('Dot file path Missing!')
  </code></pre>
  <p><strong>The graphviz dot file code is following</strong></p>
  <pre><code>digraph &quot;Call graph&quot; {
      label=&quot;Call graph&quot;;
  
      Node0x163ebe0 [shape=record,label=&quot;{external node}&quot;];
      Node0x163ebe0 -&gt; Node0x163b270;
      Node0x163ebe0 -&gt; Node0x1605360;
      Node0x163ebe0 -&gt; Node0x16052c0;
      Node0x163ebe0 -&gt; Node0x160e2a0;
      Node0x163ebe0 -&gt; Node0x160e600;
      Node0x163ebe0 -&gt; Node0x160eb00;
      Node0x160eb00 [shape=record,label=&quot;{_GLOBAL__sub_I_test.cpp}&quot;];
      Node0x160eb00 -&gt; Node0x163b200;
      Node0x163b200 [shape=record,label=&quot;{__cxx_global_var_init}&quot;];
      Node0x163b200 -&gt; Node0x163b270;
      Node0x163b200 -&gt; Node0x16052c0;
      Node0x163b270 [shape=record,label=&quot;{_ZNSt8ios_base4InitC1Ev}&quot;];
      Node0x163b270 -&gt; Node0x163e480;
      Node0x1605360 [shape=record,label=&quot;{_ZNSt8ios_base4InitD1Ev}&quot;];
      Node0x1605360 -&gt; Node0x163e480;
      Node0x16052c0 [shape=record,label=&quot;{__cxa_atexit}&quot;];
      Node0x16052c0 -&gt; Node0x163e480;
      Node0x160e2a0 [shape=record,label=&quot;{main}&quot;];
      Node0x160e2a0 -&gt; Node0x160e310;
      Node0x160e310 [shape=record,label=&quot;{_ZL1Av}&quot;];
      Node0x160e310 -&gt; Node0x160e3b0;
      Node0x160e310 -&gt; Node0x160e450;
      Node0x160e3b0 [shape=record,label=&quot;{_ZL1Bv}&quot;];
      Node0x160e3b0 -&gt; Node0x160e3e0;
      Node0x160e450 [shape=record,label=&quot;{_ZL1Gv}&quot;];
      Node0x160e450 -&gt; Node0x160e530;
      Node0x160e3e0 [shape=record,label=&quot;{_ZL1Cv}&quot;];
      Node0x160e3e0 -&gt; Node0x160e5d0;
      Node0x160e3e0 -&gt; Node0x160e670;
      Node0x160e530 [shape=record,label=&quot;{_ZL1Mv}&quot;];
      Node0x160e530 -&gt; Node0x160e850;
      Node0x160e5d0 [shape=record,label=&quot;{_ZL3WTFv}&quot;];
      Node0x160e5d0 -&gt; Node0x160e600;
      Node0x160e670 [shape=record,label=&quot;{_ZL1Xv}&quot;];
      Node0x160e670 -&gt; Node0x160e750;
      Node0x160e600 [shape=record,label=&quot;{_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc}&quot;];
      Node0x160e600 -&gt; Node0x163e480;
      Node0x160e750 [shape=record,label=&quot;{_ZL1Yv}&quot;];
      Node0x160e750 -&gt; Node0x160e5d0;
      Node0x160e850 [shape=record,label=&quot;{_ZL1Nv}&quot;];
      Node0x160e850 -&gt; Node0x160e8f0;
      Node0x160e8f0 [shape=record,label=&quot;{_ZL1Ov}&quot;];
      Node0x160e8f0 -&gt; Node0x160e990;
      Node0x160e990 [shape=record,label=&quot;{_ZL1Pv}&quot;];
      Node0x160e990 -&gt; Node0x160ea30;
      Node0x160ea30 [shape=record,label=&quot;{_ZL1Sv}&quot;];
      Node0x160ea30 -&gt; Node0x160e5d0;
  }
  </code></pre>
  <p>the main problem is I am able to iterate graph but can't mark the path from root to the required node</p>