Maybe I'm trying to bend graphviz more than I should, but would it
be possible to straighten the arrows? I need the labels to be over the arrow, not to the side as with label/xlabel; I'm using boxes to hold what is essentially label text, since using labels on the edges seems to lead to whacky behavior when the labels are long.
digraph G {
node [shape=rect style=filled
fontcolor=white fontsize=12 fontname="Helvetica Bold"]
edge [style=solid color="#777777"]
// introduce nodes; set fill
a1, a2, a3 [fillcolor="#438dd5"]
c1 [fillcolor="#08427b"]
b1, b2, b3 [fillcolor=white fontcolor=black fontname="Helvetica" shape=plain]
a1 -> b1[dir=none]
a2 -> b2[dir=none]
a3 -> b3[dir=none]
b1 -> c1
b2 -> c1
b3 -> c1
{ rankdir=LR rank=same a1 a2 a3 }
{ rankdir=LR rank=same b1 b2 b3 }
{ rankdir=LR rank=same c1 }
}
What I get:
What I want:
I usually do it using tables with no borders and white background instead of labels. You would probably also need to use headlabel or taillabel, because in this case you can precisely control their position with labeldistance and labelangle:
digraph G {
node [shape=rect style=filled
fontcolor=white fontsize=12 fontname="Helvetica Bold"]
graph [ranksep=1]
edge [style=solid color="#777777"]
a1 [fillcolor="#438dd5"]
a2 [fillcolor="#438dd5"]
a3 [fillcolor="#438dd5"]
c1 [fillcolor="#08427b"]
a1 -> c1 [
labeldistance=5
labelangle=0
headlabel=<
<table bgcolor="white" border="0">
<tr>
<td>b1</td>
</tr>
</table>
>
]
a2 -> c1 [
labeldistance=4
labelangle=0
headlabel=<
<table bgcolor="white" border="0">
<tr>
<td>b2</td>
</tr>
</table>
>
]
a3 -> c1 [
labeldistance=5
labelangle=0
headlabel=<
<table bgcolor="white" border="0">
<tr>
<td>b3</td>
</tr>
</table>
>
]
}
result:
Related
This question is a continuation of this question.
In addition to strictly east-to-west arcs, I would also like them to be orthogonal (ie not curved.) So I added the attribute "splines=ortho" to the dot file, like this:
digraph net {
graph [splines=ortho]
"C0" [shape=oval label="C0"]
"C1" [shape=oval label="C1"]
"B0" [shape=box label="B0"]
rankdir="LR"
"C0":e -> "B0":w
"B0":e -> "C1":w
"C1":e -> "B0":w
}
Now I am getting this image, where the arcs are going through the nodes:
Is it possible to get a picture like this, where the orthogonal arc moves around the nodes, something like this?
It is possible, but you have to DIY. Here we add lots of invisible nodes and then "connect the dots" (puns!).
Note the use of dir (https://graphviz.org/docs/attrs/dir/), headclip (http://www.graphviz.org/docs/attrs/headclip/), and tailclip (https://graphviz.org/docs/attrs/tailclip/) attributes.
digraph net {
graph [splines=false]
// rankdir="LR" << turned it off, makes things easier?
graph [nodesep=.07]
{
node [style=invis label=""]
I1 I2 I3 I4 I5 I6 X2 X4 X6
}
{rank=same I1 I2 I3 I4 I5 I6}
{rank=same C0 B0 C1 X2 X4 X6}
"C0" [shape=oval label="C0"]
"C1" [shape=oval label="C1"]
"B0" [shape=box label="B0"]
C0 -> X2 [dir=none headclip=false]
X2 -> B0 [tailclip=false]
B0 -> X4 [dir=none headclip=false]
X4 -> C1 [tailclip=false]
C1 -> X6 [dir=none headclip=false]
{
edge [dir=none tailclip=false headclip=false]
I6 -> X6
I2 ->I3 ->I4 -> I5 ->I6
}
I2 -> X2 [tailclip=false headclip=false]
}
Giving:
I have a graph like this:
Question 1: Is there a way to align the two columns horizontally in the top?
If I want to have an arrow a5 -> a1, then the graph would be:
Question 2: Is there a way to keep the graph as clean as before?
Here is the code:
digraph {
rankdir="LR";
// overlap=false;
nodesep="0.2";
ranksep="0.4";
fontsize = 25
labelloc="t";
fontname="Lato";
node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ]
edge [ fontname="Lato" color="#2B303A" ]
subgraph cluster_0 {
style=filled;
color=lightgrey;
label = "Column 1";
fontsize = 20
node [style=filled,color=white];
a1
a2
a3
a4
a5
}
subgraph cluster_1 {
node [style=filled];
color=blue
label = "Column 2";
fontsize = 20
// labeljust=r
// labelloc=b
b1
b2
b3
b4
}
a1 -> b1
b1 -> a2
a2 -> b2
b2 -> a3
a3 -> b3
b3 -> a4
a4 -> b4
b4 -> a5
a5 -> a1
}
Two minor steps are needed:
(1) Put all a nodes in the same rank. If you don't, graphviz establishes a hierarchical relationship between a1 and a5, that's what your graph shows.
(2) Add some extra weight to the edge between a1 and b1, to keep it straight.
digraph {
rankdir="LR";
// overlap=false;
nodesep="0.2";
ranksep="0.4";
fontsize = 25
labelloc="t";
fontname="Lato";
node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ]
edge [ fontname="Lato" color="#2B303A" ]
subgraph cluster_0 {
style=filled;
color=lightgrey;
label = "Column 1";
fontsize = 20
node [style=filled,color=white];
{rank = same; a1 a2 a3 a4 a5 } // !!!
}
subgraph cluster_1 {
node [style=filled];
color=blue
label = "Column 2";
fontsize = 20
// labeljust=r
// labelloc=b
b1
b2
b3
b4
}
a1 -> b1[ weight = 10 ]; // !!!
b1 -> a2
a2 -> b2
b2 -> a3
a3 -> b3
b3 -> a4
a4 -> b4
b4 -> a5
a5 -> a1
}
now produces
I'd go about this with the two following changes:
Use constraint=false in order to not have the edge from a5 to a1 mess up the graph
use the group attribute to suggest straight edges between nodes (same attribute value for nodes that should be placed in a straight line when connected with an edge)
digraph {
rankdir="LR";
// overlap=false;
nodesep="0.2";
ranksep="0.4";
fontsize = 25
labelloc="t";
fontname="Lato";
node [ shape="plaintext" style="filled, rounded" fontname="Lato" margin=0.2 ]
edge [ fontname="Lato" color="#2B303A" ]
subgraph cluster_0 {
style=filled;
color=lightgrey;
label = "Column 1";
fontsize = 20
node [style=filled,color=white];
a1 [group=1]
a2
a3
a4
a5
}
subgraph cluster_1 {
node [style=filled];
color=blue
label = "Column 2";
fontsize = 20
// labeljust=r
// labelloc=b
b1 [group=1]
b2
b3
b4
}
a1 -> b1
b1 -> a2
a2 -> b2
b2 -> a3
a3 -> b3
b3 -> a4
a4 -> b4
b4 -> a5
a5 -> a1 [constraint=false]
}
I want to draw a clean network graph like this image.
But I couldn't find how can I do this. I have to use css for removing part of cell border line, but, as far as I know, dot file is not supported css. I want to insert ellipse shape node, separate node with vertical bar,
How can I draw a graph that satisfies these conditions? My dot file has self loop, so I can't use networkx. Any other ways are exist? or can I solve use dot file?
My dot file code is
digraph {
// size = "6,8.5";
// ratio = "fill";
// layout = "circo"
forcelabels = True;
graph[overlap=False];
node [shape = ellipse];
node [fontsize = 10];
// node [penwidth = 3];
edge [fontsize = 10];
// A [pos = "0,2"]
// B [pos = "-2,-2"]
// C [pos = "0,1"]
// D [pos = "2,-2"]
// E [pos = "0,-3"]
A
B
C
D
E;
node[shape = point];
x1[style = invis]
{rank=same; A,C}
{rank=same; B,E}
A -> C [label = "4|1.0\l"];
B -> B [label = "1|:0.979\l"];
C:nw -> C:ne [label = "3|0.167\l"];
C -> D [label = "5|0.115\l"];
D:nw -> C:sw [xlabel = "3|0.103\l4|0:0.315\l"];
D:se -> x1 [dir = none]
x1 -> D:sw [xlabel = "5|0.308\l6|0:0.253\l"];
E -> B [label = "4|0.5\l"];
E -> D [label = "6|0.5\l"];
}
Two ways to create your nodes, one fairly close (well to my eyes) and pretty easy to replicate. The other will allow you to recreate your example, but requires using two programs (dot and a program to create individual nodes in svg - like Inkscape)
digraph structs {
// if oblong is good enough, this works
node [shape=none]
try3 [label=<
<TABLE border="1" cellborder="0" cellspacing="0" cellpadding="0" style="rounded" >
<TR><TD width="40">A</TD><VR/><TD width="40">*111<BR/>*101<BR/>*011</TD></TR>
</TABLE>>];
// if you really want a circular node, perfectly split
// create the node images with another program (like Inkscape)
// and include as an image
try5 [image="/tmp/split1.svg" label=""]
}
producing:
I'm interested in drawing vertical ellipsis between nodes in graphviz like seen below:
The problem I'm having is whenever I try to do this I cannot seem to get x3 and xn to line up vertically as seen here:
Here is what I have tried:
digraph G {
rankdir=LR
splines=line
subgraph cluster_0 {
color=white;
node [style=solid, color=black, shape=circle];
x1 x2 x3 xn [group=g1];
label = "Input Features";
}
subgraph cluster_1 {
color=white;
node [style=solid, color=red2, shape=circle];
a1 [group=g2];
label = "Activation";
}
subgraph cluster_2 {
color=white;
node [style=solid, color=green, shape=circle];
out [group=g3];
label = "Output";
}
x1 -> a1;
x2 -> a1;
x3 -> a1;
a1 -> out;
x3 -> xn [arrowhead="none", color="black:invis:black"];
}
I'm very new to graphviz so I'm not even sure if I'm using subgraph properly here. I also tried adding the nodes in the subgraphs to groups, but that didn't seem to do anything.
Add
{ rank = same; x1 x2 x3 xn }
x1 -> x2 -> x3[ style = invis ];
to your first subgraph. This has the effect that
the four nodes are all one one level, i.e. lining up vertically
the three numbered nodes stay together
Here my version:
digraph G
{
rankdir = LR
splines = line
subgraph cluster_0
{
color = white;
node[ style = solid, color = black, shape = circle];
{ rank = same; x1 x2 x3 xn }
x1 -> x2 -> x3[ style = invis ];
label = "Input Features";
}
subgraph cluster_1
{
color = white;
node[ style = solid, color = red2, shape = circle ];
a1;
label = "Activation";
}
subgraph cluster_2
{
color =white;
node[ style = solid, color = green, shape = circle ];
out;
label = "Output";
}
x1 -> a1;
x2 -> a1;
x3 -> a1;
a1 -> out;
x3 -> xn[ arrowhead = "none", color = "black:invis:black" ];
}
which gives you
E D I T to answer the question in your comment; the key is reversing the order of node definitions and edge direction within the same rank, probably caused by the rankdir = LR layout. After all, there is a simple solution!
digraph G
{
rankdir = LR
splines = line
subgraph cluster_0
{
color = white;
label = "Input Features";
node[ style = solid, color = black, shape = circle ];
/* define and connect in reverse order */
{ rank = same; xn x3 x2 x1 }
x3 -> x2 -> x1[ style = invis ];
xn -> x3[ arrowhead = "none", color = "black:invis:black" ];
}
subgraph cluster_1
{
color = white;
node[ style = solid, color = red2, shape = circle ];
a1;
label = "Activation";
}
subgraph cluster_2
{
color =white;
node[ style = solid, color = green, shape = circle ];
out;
label = "Output";
}
{ x1 x2 x3 } -> a1;
a1 -> out;
}
I would like to show the diagram below, except with the two tables on the same horizontal level. I would like the second table to be shown to the right of the first table and not below it like it is currently.
The current code for graphviz that I have is:
digraph G {
node [shape=record, fontname="Arial"];
set1 [label = "{Blue Crosses | B1 | B2 | B3 | B4 }|{ Square |<b1> Left |<b2> Left |<b3> Right | Left }"];
set2 [label = "{Blue Crosses |<b1> B1 |<b2> B2 |<b3> B3 }|{ Coordinates | (1, 1) | (2, 2) | (4, 2) }"];
set1:b1 -> set2:b1;
set1:b2 -> set2:b2;
set1:b3 -> set2:b3;
}
In order to achieve what you want, you need to add the line
{ rank = same; set1 set2 }
to your code after you have created the nodes. However, in this situation, you will find that graphviz gets confused and doesn't recognise the ports anymore. So instead of using record = shape you will need to re-code your graph with HTML-like labels. I have done that for the example provided (thanks for a clear question with code and desired outcome, by the way):
digraph G
{
node[ shape = none, fontname = "Arial" ];
set1[ label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
<TD>Blue Crosses</TD>
<TD>Square</TD>
</TR>
<TR>
<TD>B1</TD>
<TD PORT="b1">Left</TD>
</TR>
<TR>
<TD>B2</TD>
<TD PORT="b2">Left</TD>
</TR>
<TR>
<TD>Right</TD>
<TD PORT="b3">Right</TD>
</TR>
<TR>
<TD>B4</TD>
<TD>Left</TD>
</TR>
</TABLE>>];
set2[ label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
<TD>Blue Crosses</TD>
<TD>Coordinates</TD>
</TR>
<TR>
<TD PORT="b1">B1</TD>
<TD>(1, 1)</TD>
</TR>
<TR>
<TD PORT="b2">B2</TD>
<TD>(2, 2)</TD>
</TR>
<TR>
<TD PORT="b3">B3</TD>
<TD>(4, 2)</TD>
</TR>
</TABLE>>];
# layout
nodesep = 2; /* increase distance between nodes */
{ rank = same; set1 set2 }
set1:b1 -> set2:b1;
set1:b2 -> set2:b2;
set1:b3 -> set2:b3;
}
yields