# Simulate Y axis and horizontal strips

**URL:** <https://forum.graphviz.org/t/simulate-y-axis-and-horizontal-strips/2723>\
**Category:** Help\
**Created:** [February 14, 2025, 9:41am UTC](https://forum.graphviz.org/t/simulate-y-axis-and-horizontal-strips/2723 "2025-02-14T09:41:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![somms](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/somms/32/1839_2.png) [@somms](https://forum.graphviz.org/u/somms)\
**Post date:** [February 14, 2025, 9:41am UTC](https://forum.graphviz.org/t/simulate-y-axis-and-horizontal-strips/2723/1 "2025-02-14T09:41:33Z")

</div>

Hi everybody,  
I am trying to create a graph placing nodes in layers, order by its centrality. I have managed to group them using ranks and order them using invisible rank nodes and edges. I also managed to add two “Y axis”. This is the code ([Graphviz Online](https://tinyurl.com/2ww27y85)) and resulting graph

[dot verbose=true]

```auto
digraph prof {
    graph[splines=yes];
    rankdir="TB";
    layout="dot";
    node [fontname="Helvetica", fontcolor="white"];
    edge [style=bold, color="#888"]
    fontsize=12;
    
    
    // =============================
    // Centrality Y axis
    // =============================
    subgraph cluster_legend {
        layout="dot";
        label="Centralidad";
        fontname="Helvetica";
        color=transparent;
        penwidth=2;
        
        subgraph cluster_legend_nodes{
            label="";
            peripheries=0;
            node [fontname="Helvetica", fontcolor="black", penwidth=3];
            scale_0 [label="0", height=.8, color=transparent, shape=square];
            scale_05 [style=invisible];
            scale_1 [label="2", height=.8, color=transparent, shape=square];
            scale_15 [style=invisible];
            scale_2 [label="4", height=.8, color=transparent, shape=square];
            scale_25 [style=invisible];
            scale_3 [label="6", height=.8, color=transparent, shape=square];
            scale_35 [style=invisible];
            scale_4 [label="8", height=.8, color=transparent, shape=square];
            
            scale_4 -> scale_35 -> scale_3 [style=line, arrowhead=none];
            scale_3 -> scale_25 -> scale_2 [style=line, arrowhead=none];
            scale_2 -> scale_15 -> scale_1 [style=line, arrowhead=none];
            scale_1 -> scale_05 -> scale_0 [style=line, arrowhead=none];
        }
    }
    
    
    // Invisible nodes to control order
    rank2 [style=invisible, group=2];
    rank3 [style=invisible, group=3];
    rank4 [style=invisible, group=4];
    rank5 [style=invisible, group=5];
    rank6 [style=invisible, group=6];
    rank7 [style=invisible, group=7];
    rank8 [style=invisible, group=8];
    rank9 [style=invisible, group=9];
    rank10 [style=invisible, group=10];
    
    // Invisible edges to maintain vertical order and distance

    rank2 -> rank3 [style=invis];
    rank3 -> rank4 [style=invis];
    rank4 -> rank5 [style=invis];
    rank5 -> rank6 [style=invis];
    rank6 -> rank7 [style=invis];
    rank7 -> rank8 [style=invis];
    rank8 -> rank9 [style=invis];
    rank9 -> rank10 [style=invis];

    // =============================
    // Real nodes definition
    // =============================

    // Objetivos
    1 [label="OB1", style=filled, fillcolor="red", color="red", penwidth=4, shape=square, group=7];
    2 [label="OB2", style=filled, fillcolor="red", color="red", penwidth=4, shape=square, group=2];
    3 [label="OB3", style=filled, fillcolor="red", color="red", penwidth=4, shape=square, group=5];
    4 [label="OB4", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=square, group=6];
    5 [label="OB5", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=square, group=5];
    6 [label="OB6", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=square, group=6];
    7 [label="OB7", style=filled, fillcolor="green", color="green", penwidth=4, shape=square, group=5];
    8 [label="OB8", style=filled, fillcolor="green", color="green", penwidth=4, shape=square, group=8];
    9 [label="OB9", style=filled, fillcolor="green", color="green", penwidth=4, shape=square, group=8];
    10 [label="OB10", style=filled, fillcolor="green", color="green", penwidth=4, shape=square, group=6];

    // Actuaciones
    11 [label="AC1", style=filled, fillcolor="red", color="red", penwidth=4, shape=circle, group=5];
    12 [label="AC2", style=filled, fillcolor="red", color="red", penwidth=4, shape=circle, group=7];
    13 [label="AC3", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=circle, group=6];
    14 [label="AC4", style=filled, fillcolor="red", color="red", penwidth=4, shape=circle, group=7];
    15 [label="AC5", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=circle, group=9];
    16 [label="AC6", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=circle, group=6];
    17 [label="AC7", style=filled, fillcolor="blue", color="blue", penwidth=4, shape=circle, group=8];
    18 [label="AC8", style=filled, fillcolor="green", color="green", penwidth=4, shape=circle, group=7];
    19 [label="AC9", style=filled, fillcolor="green", color="green", penwidth=4, shape=circle, group=9];
    20 [label="AC10", style=filled, fillcolor="green", color="green", penwidth=4, shape=circle, group=7];
    
    {rank=min;rank2;2}
    {rank=same;rank5;3;5;7;11}
    {rank=same;rank6;4;6;10;13;16}
    {rank=same;rank7;1;12;14;18;20}
    {rank=same;rank8;8;9;17}
    {rank=same;rank9;15;19}

     // =============================
    // Links
    // =============================
    
    1 -> 2 ;
    1 -> 5 ;
    1 -> 11 ;
    2 -> 1 ;
    2 -> 5 ;
    2 -> 12 ;
    2 -> 13 ;
    5 -> 1 ;
    5 -> 3 ;
    3 -> 5 ;
    5 -> 15 ;
    3 -> 2 ;
    3 -> 7 ;
    3 -> 13 ;
    7 -> 10 ;
    7 -> 17 ;
    4 -> 3 ;
    4 -> 9 ;
    4 -> 14 ;
    4 -> 11 ;
    9 -> 19 ;
    6 -> 7 ;
    6 -> 2 ;
    6 -> 16 ;
    10 -> 20;
    8 -> 10 ;
    8 -> 18 ;
    11 -> 10;
    11 -> 16;
    13 -> 5 ;
    13 -> 12;
    14 -> 7 ;
    14 -> 11;
    16 -> 2 ;
    16 -> 20;
    17 -> 12;
    18 -> 2 ;
    18 -> 6 ;
    20 -> 2 ;

    // =============================
    // Second centrality Y axis
    // =============================
    subgraph cluster_legend_bis {
        layout="dot";
        label="Centralidad";
        fontname="Helvetica";
        color=transparent;
        penwidth=2;
        
        subgraph cluster_legend_nodes_bis{
            label="";
            peripheries=0;
            node [fontname="Helvetica", fontcolor="black", penwidth=3];
            scale_0_bis [label="0", height=.8, color=transparent, shape=square];
            scale_05_bis [style=invisible];
            scale_1_bis [label="2", height=.8, color=transparent, shape=square];
            scale_15_bis [style=invisible];
            scale_2_bis [label="4", height=.8, color=transparent, shape=square];
            scale_25_bis [style=invisible];
            scale_3_bis [label="6", height=.8, color=transparent, shape=square];
            scale_35_bis [style=invisible];
            scale_4_bis [label="8", height=.8, color=transparent, shape=square];
            
            scale_4_bis -> scale_35_bis -> scale_3_bis [style=line, arrowhead=none];
            scale_3_bis -> scale_25_bis -> scale_2_bis [style=line, arrowhead=none];
            scale_2_bis -> scale_15_bis -> scale_1_bis [style=line, arrowhead=none];
            scale_1_bis -> scale_05_bis -> scale_0_bis [style=line, arrowhead=none];
        }
    }
}

```

[/dot]

Now I want to add **horizontal background stripes or lines to separate each centrality level** , going from the left axis to the right axis. I have tried to create subgraphs for every level, adding the corresponding nodes, but it does not work well.

Do you have any idea?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)\
**Post date:** [February 14, 2025, 3:20pm UTC](https://forum.graphviz.org/t/simulate-y-axis-and-horizontal-strips/2723/2 "2025-02-14T15:20:34Z")

</div>

If you can use a two-pass solution, this may provide the solution:

> [@Add a grid to your graphs](https://forum.graphviz.org/t/add-a-grid-to-your-graphs/2402):
>
> addGrid.gvpr - a postprocessor that will add a grid to your Graphviz graph. [unix.Ranks] Find it [here](https://gist.github.com/steveroush/325b594e0547e2abbc79c5106d8e8db3) It can do horizontal, vertical, or both; edge styles, (multiple) colors, fixed increment or centered on ranks. Mostly a toy, but probably useful on larger graphs. Example command line: dot myFile.gv | gvpr -a 'size=rank Gcolor=green,purple,red grid=horizontal' -cf addGrid.gvpr |neato -n2 ... Enjoy

p.s. **style=line** is not supported, you want **style=solid**

---

<div class="post-metadata">

**Author:** ![somms](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/somms/32/1839_2.png) [@somms](https://forum.graphviz.org/u/somms)\
**Post date:** [February 14, 2025, 4:50pm UTC](https://forum.graphviz.org/t/simulate-y-axis-and-horizontal-strips/2723/3 "2025-02-14T16:50:17Z")

</div>

Thanks a lot, Steve. I can use GVPR, yes. I will give this a try.  
And thanks for the correction.

---

<div class="post-metadata">

**Author:** ![magjac](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/magjac/32/16_2.png) [@magjac](https://forum.graphviz.org/u/magjac)\
**Post date:** [February 14, 2025, 5:27pm UTC](https://forum.graphviz.org/t/simulate-y-axis-and-horizontal-strips/2723/4 "2025-02-14T17:27:28Z")

</div>

I took the liberty to edit your post so that the DOT source in shown (I added [`verbose=true`](https://forum.graphviz.org/t/render-graphviz-graphs-directly-in-your-posts/125#the-verbose-option-14)).

---

<div class="post-metadata">

**Author:** ![somms](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/somms/32/1839_2.png) [@somms](https://forum.graphviz.org/u/somms)\
**Post date:** [February 14, 2025, 5:41pm UTC](https://forum.graphviz.org/t/simulate-y-axis-and-horizontal-strips/2723/5 "2025-02-14T17:41:24Z")

</div>

This is not directly related to my question but to the usage of your gvpr file.  
When I try to add any parameter using the -a option, I always get an empty output and a “gvpr: gvpr” message:

```auto
$ dot input.dot | gvpr -a 'size=rank' -cf addGrid.gvpr
// SIZE start: 72pt delta: 0
// SIZE end: 72pt size: 72 delta: 0
// ARG >size=rank<
// type: s
gvpr: gvpr

```

I can move this subthread to the “Add a grid to your graphs”
