Graphviz决策树分别显示相同的元素

时间:2019-01-02 03:47:45

标签: python-3.x graphviz

我在这里有代码

import Adafruit_PCA9685
pwm = Adafruit_PCA9685.PCA9685()

pwm.set_pwm_freq(60)

# Demo using LED on Channel 12 of the PCA9685
# Wire up the LED  on  Channel 12 such that 
#    Shortleg of LED goes to GND and
#    Long leg goes to PWM pin on channel 12

pwm.set_pwm(12,0,4095)   # Full bright
time.sleep(5)

pwm.set_pwm(12,1024,3072) # half bright
time.sleep(5)

pwm.set_pwm(12,0,0)  #off
time.sleep(5)

输出如图所示:

enter image description here

如何获得这样的图形:

enter image description here

1 个答案:

答案 0 :(得分:1)

不使用Python,我只有一个纯粹的graphviz答案,但是您应该可以轻松地将其翻译成Python。

您需要做两件事:

  • 创建四个节点,而不是三个,并为其指定所需标签
  • 将要在同一级别上具有的节点放入rank = same指令中(在示例上下文中并非严格必要,但对于更复杂的图形可能是必需的)

我们在这里:

digraph so 
{
    n_1[ label = "a" ];
    n_2[ label = "b" ];
    n_3[ label = "c" ];
    n_4[ label = "c" ];

    { rank = same; n_2 n_3 }

    n_1 -> { n_2 n_3 };
    n_2 -> n_4;
}

给你

enter image description here