How to place Graphviz labels to avoid edges - graphviz

digraph {
X -> Y [xlabel="80"]
Y -> Z [xlabel="60"]
Z -> X [xlabel="3"]
Y -> X [xlabel="1"]
}
I render the Graphviz dot file above using:
dot -Tpng a.dot -o a.png
but find that the output image, shown below, has the edges and arrowheads overlapping with the labels.
I've tried a variety of approaches without success, and so I've reverted here to a simple example. I'm betting there's actually an obvious flag to get past this issue. Can anyone help?

Don't use external labels (xlabel), but standard labels (label).
Using standard labels in your example produces no overlapping.

Related

Graphviz: create non overlapping edges from a struct to itself

I am trying to recreate in graphviz a diagram similar to the one taken from the CLR book:
I am using the following code in Python:
s = Digraph(node_attr={'shape': 'record'})
s.node('struct', '<f0> 3|<f1> 13|<f2> 1|<f3> 2|<f4> 8|<f5> 5')
s.edge("struct:f0", "struct:f1")
s.edge("struct:f0", "struct:f2")
s.edge("struct:f1", "struct:f3")
s.edge("struct:f1", "struct:f4")
s
The result is:
Which is very close to what I want, except the edges overlap the nodes instead of going above/below them.
I couldn't find a way to modify edge behavior. Also, I have a feeling I am misusing the struct feature of graphviz, but I don't know how to force the graph elements to stick together in one row otherwise.
Can I avoid edge overlaps (except by modifying the SVG myself, of course) or use a different approach altogether?
You can use "ports" to set the points of connection.
I tried your graph on the online service, it seems your rendering is with dot http://dreampuf.github.io/GraphvizOnline
You can test with the others, Circo and the rest do not cross the cells, but by default they all draw on one side (bottom) and the edges are messy.
However there are "ports" properties which allow to solve that by specifying suffixes ":s", ":n" etc. n, s, e, w, nw, ne, sw, s. - i.e. south, north etc.... .
It seems that Dot has different default ports than Circo and Neato, the latter are fine with that:
digraph Structs {
node [shape=record];
s [label="<f0> 3|<f1> 13|<f2> 1|<f3>2|<f4>8|<f5>5"];
s:f0 -> s:f1;
s:f0 -> s:f2;
s:f1:n -> s:f3:n;
s:f1:n -> s:f4:n;
}
Dot needs to specify the ports of the first two nodes, too:
digraph Structs {
node [shape=record];
s [label="<f0> 3|<f1> 13|<f2> 1|<f3>2|<f4>8|<f5>5"];
s:f0:s -> s:f1:s;
s:f0:s -> s:f2:s;
s:f1:n -> s:f3:n;
s:f1:n -> s:f4:n;
}
So I guess, in your code:
s.edge("struct:f0:s", "struct:f1:s")
s.edge("struct:f0:s", "struct:f2:s")
s.edge("struct:f1:n", "struct:f3:n")
s.edge("struct:f1:n", "struct:f4:n")
See: How to prevent edges in graphviz to overlap each other
Graphviz Dot Edge Ports for Family Tree

Graphviz with nodes and edges in Russian: edge label has offset and Node is enlarged

I'm drawing diagram with graphviz. I set node and edge labels in Russian. Nodes with Russian labels are much larger than nodes with English labels with the same length. Also edge labels in Russian have offset that labels in English doesn't have.
I tried to use different graphviz tools such as: viz-js.com, Atom editor with graphviz plugin, gvedit. Only gvedit provides correct result, but I can't use it.
Here is sample code:
digraph D {
Anton -> Антон [label="Метка"]
Anton -> Bob [label="Label"]
}
Result is:
Not really an solution / answer but some observations and it is a bit long for a comment.
I tried the given file directly with dot version 2.38.0 (20140413.2041) and got as result:
I also tried with version version 2.40.1 (20161225.0304) and got the same result.
So I think the underlying dot program is working correct.
I also tried http://www.webgraphviz.com/ but here I get the message:
Warning: :3: string ran past end of line Error: :3: syntax error near line 3
and the resulting image is even worse:
So here it looks like the used input encoding is not correct, this might also be the case with the tools OP used.

How to print comments at the right side of a matlab graph?

I want to plot only one simple set of data. For example, my plot command could be :
x = (1:10);
y = ones[1,10];
plot(x,y);
In fact, the y data set could have been generated by a previous code, depending on several parameters. I want to print the name of every parameters and there values outside the graph, at the right of it, as if it were a legend. My problem is that I have several parameters to print, but only one set of data.
I tried to do this by the text or legend functions, but it never fit completly my needs.
Could you help me please ?
I think this code should help you out. Its probably easiest to split your figure into two axes, the right one just to hold text:
x = rand(1,10);
y = rand(1,10);
figure % makes your figure
axes('Position', [0.05,0.05,0.45,.9]) % makes axes on left side of your figure
scatter(x,y)
axes('Position', [0.55,0,1,1],'ytick',[],'xtick',[]) %make axes on left side of your figure, turns of ticks
text(0.05,0.85,{'Parameter 1: blah blah';'Parameter 2: bloop bloop';'Parameter 3: ....'},'Interpreter','Latex')
Play around with the numbers in the brackets to resize things as you like.

Display labels in line with the edge when using Graphviz

I am using Graphviz 2.30. Horizontal positioning for labels works out, but in a few cases, a modified angle would be desired.
For instance, I tried various values for angle here but without any effect:
ABB -> ABACUS[label="applied", fontname="Arial", fontsize=15, labelangle=110];
How can I display labels in line with (i.e. parallel to) the edge when using a Graphviz digraph.
The entire digraph will not be posted due to an NDA. In addition, the rotation will be applied only to a few labels.
I have read similar threads like this or another (or a thread about alignment for instance) but without any help regarding my issue.
Using dot2latex allows you to specify lblstyle attribute. The value of lblstyle is used by PGF/TikZ in pdf generation.
One can specify parallel labels like this:
digraph G {
edge [lblstyle="above, sloped"];
a -> b [label="ab"];
b -> c [label="bc"];
c -> a [label="ca"];
}
To generate the pdf
$ dot2tex --tikzedgelabel file.dot > file.tex
$ pdflatex file.tex
The result is
Edit: another answer found an option that now exists to align text with edges.
Your best option may be to export the graph as an SVG and use Illustrator or Inkscape to fine-tune it. This is only practical when producing a few graphs.
I frequently have to tweak the output from Graphviz and Gephi; they give me a good starting point though.

How to strike-through text in dot language (graphviz)

I am trying to find out how can I strike-through some text in my nodes in dot based graphviz diagrams?
I checked out on this page, but couldn't figure out:
http://www.graphviz.org/doc/info/attrs.html
Googling around didn't help as well.
Consider this diagram, these are basically bug numbers from a bugzilla. The red nodes represent closed bugs, but I do not want to color code them like this. Obviously striken-through 511272 is more intuitive than a red colored node 511272.
If anyone knows how to strike-through text inside nodes, please share.
thanks,
Shobhit
Graphviz does not have a styling of its own to do this, but since it is Unicode you can use the technique with combining characters and "combining long stroke overlay" (U+0336) that the wikipedia article on strikethrough suggests:
In plain text scenarios where markup cannot be used, Unicode offers a number of combining characters that achieve similar effects.
The "long stroke overlay" (U+0336) results in an unbroken stroke
across the text,
Separate: A̶B̶C̶D̶E̶F̶G̶H̶I̶
Combined: A̶B̶C̶D̶E̶F̶G̶H̶I̶
This graph:
digraph G {
a [label="1̶2̶3̶4̶5̶"]
b [label="54321"]
a->b
}
Renders this png output with graphviz 2.23.6:
Aother option is to use HTML-like labels:
digraph G {
a [label=<<s>12345</s>>]
b [label="54321"]
a->b
}

Resources