'How to add annotations anywhere in flowchart, schemdraw

I am new to Python.

I'm creating this flowchart, and I'd like to add some captions (Subtitle 1, 2 and 3) to the boxes. However, I don't know how to make such annotations.

Also, I would like to expand the area of the boxes (red, blue and green).

Please, could someone help me with this?

pip install schemdraw
import schemdraw
import schemdraw.elements as elm

with schemdraw.Drawing() as d:
    d.config(fontsize=14)
    d += (b := flow.Start(w=6, h=2).label('Start'))
    d += flow.Arrow().down(d.unit/2)
    
    d += (step1 := flow.Box(w=8, h=2).label('Thing 1').fill(''))
    d += flow.Arrow().down(d.unit/2)
    d += (step2 := flow.Box(w=8, h=2).label('Thing 2').fill(''))
    d += flow.Arrow().down(d.unit/2)
    d += (step3 := flow.Box(w=8, h=2).label('Thing 3').fill(''))
    
    d += flow.Arrow().down(d.unit/2)
    d += (step4 := flow.Box(w=8, h=2).label('Thing 4').fill(''))
    d += flow.Arrow().down(d.unit/2)
    d += (step5 := flow.Box(w=8, h=2).label('Thing 5').fill(''))
    d += flow.Arrow().down(d.unit/2)
    d += (step6 := flow.Box(w=8, h=2).label('Thing 6').fill(''))
    
   
    # Activities
    d += flow.Arrow().right(d.unit/2).at(step1.E)
    d += (act1 := flow.Box(w=8, h=2).anchor('W').label('activity 1').fill(''))
    
    d += flow.Arrow().right(d.unit/2).at(step2.E)
    d += (act2 := flow.Box(w=8, h=2).anchor('W').label('activity 2').fill(''))

    d += flow.Arrow().right(d.unit/2).at(step3.E)
    d += (act3 := flow.Box(w=8, h=2).anchor('W').label('activity 3').fill(''))
 
    d += flow.Arrow().right(d.unit/2).at(step4.E)
    d += (act4 := flow.Box(w=8, h=2).anchor('W').label('activity 4').fill(''))
    
    d += flow.Arrow().right(d.unit/2).at(step5.E)
    d += (act5 := flow.Box(w=8, h=2).anchor('W').label('activity 5').fill(''))

    d += flow.Arrow().right(d.unit/2).at(step6.E)
    d += (act6 := flow.Box(w=8, h=2).anchor('W').label('activity 6').fill(''))
 
    d += (phase1 := elm.EncircleBox([step1, step2, step3, act1, act2, act3], padx=.8).linestyle('--').linewidth(2).color('red'))
    d += (phase2 := elm.EncircleBox([step4, step5, act4, act5], padx=.8).linestyle('--').linewidth(2).color('blue'))
    d += (phase3 := elm.EncircleBox([step6, act6], padx=.8).linestyle('--').linewidth(2).color('green'))

    #d += elm.Label().label('Parallel',loc="top").color('red')

enter image description here

Thanks in advance.



Solution 1:[1]

You can add labels to the EncircleBox elements, just like any other element. But by default it will appear above the box, so you need to specify the location and a rotation of 90 degrees:

d += (phase1 := elm.EncircleBox([step1, step2, step3, act1, act2, act3], padx=2, pady=.5).linestyle('--').linewidth(2).color('red')
         .label('Subtitle 1', loc='left', rotate=90))
d += (phase2 := elm.EncircleBox([step4, step5, act4, act5], padx=2, pady=.5).linestyle('--').linewidth(2).color('blue')
         .label('Subtitle 2', loc='left', rotate=90))
d += (phase3 := elm.EncircleBox([step6, act6], padx=2, pady=.5).linestyle('--').linewidth(2).color('green')
         .label('Subtitle 3', loc='left', rotate=90))

The padx and pady parameters make the EncircleBoxes bigger in the x and y directions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Collin