graphviz dot to pdf: distance from graph to title - dot

in graphviz dot, generating pdf output.
how do I increase the distance between the title and the graph?
digraph "test" {
graph [ label="need more distance to below" ];
A -> B;
}
advice appreciated.

Not preferable solution but Append "\n" at the end of label. If you need more space add more "\n".

Related

How to show arrows symmetrically for self-loops in a dot graph

I am working with a DFA which I have described in the dot file format. One of the nodes in my DFA has two self-loops, which I originally described with the following way
digraph {
rankdir=LR;
a -> a [color=blue]
a -> a [color=green]
}
Which produces this output when I run dot graph.gv -Tpng
For symmetry reasons, I'd like to have the blue and the green arrows on opposite sides of the node. I can modify the headport and tailport of the green arrow to force it to start from the bottom of the node as follows:
digraph {
rankdir=LR;
a -> a [color=blue]
a:sw -> a:se [color=green]
}
Unfortunately, that produces an absolutely wonky output:
What's the correct way of getting the two arrows to be symmetrically opposite each other on the node?
I doubt you have a lot of control over the edge layout. But you can experiment with the headport attribute values. Here are some examples.
Example 1
digraph {
rankdir=LR;
a:n -> a [color=blue]
a:s -> a [color=green headport=center]
}
View in editor
Example 2
digraph {
rankdir=LR;
a:ne -> a [color=blue]
a:sw -> a [color=green headport=center]
}
View in editor
Other layouts
You can also experiment with different layouts. Here are some options for the circo layout.
Example 3
digraph {
rankdir=LR;
layout="circo"
a:n -> a:_ [color=blue headport=n]
a:s -> a:_ [color=green headport=s dir=back]
}
View in editor
Example 4
digraph {
rankdir=LR;
layout="circo"
a:nw -> a:w [color=blue headport=_]
a:se -> a:e [color=green headport=_]
}
View in editor

Graphviz Composite Structure Diagram

Is it possible to generate with Graphviz / dot a UML composite structure diagram like the one below?
By using (open) box arrowheads https://graphviz.gitlab.io/doc/info/arrows.html, this gets pretty close:
digraph boxed {
graph [splines=ortho nodesep =.75]
node [shape=box]
edge [dir=both arrowtail=obox arrowhead=obox]
{ rank=same
x1 -> x2 -> x3
}
x1:s -> y1:n
}

R DiagrammeR Flush Subscript and Superscript within Labels

Long time reader, first time poster.
I am attempting to write mechner notation using DiagrammeR (through R Studio; everything is up to date; MacOS). Long term intention is to embed the code within a latex doc, but I'm taking this one step at a time. Currently, I cannot find the code necessary to force a subscript and superscript to be in-line with each other. So far, I have found this:
library(DiagrammeR)
grViz("
digraph dot {
graph [layout = dot, rankdir = LR]
node [fontname = Helvetica, shape = plaintext]
a [label = 'aA']
b [label = 'bA#_{2}#^{p}']
c [label = 'abC']
a -> b -> c
}")
Produces this.
But I need this.
I suppose the real question is how to properly format within those pesky quotations. I have yet to find a walkthrough on how to properly format (e.g., bold, italics, superscript) within the label field quotations. Suggestions?
I figured this out and forgot to post an answer! Here is the code that worked for me (Mac OSx; R Studio Sweave File, w/ pdfLaTeX enabled):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\newcommand{\1}{\textbf} %to save space
\begin{document}
\SweaveOpts{concordance=TRUE}
%example 1
\par{\centering
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, nodes in empty cells, row
sep=1em,column sep=2em,minimum width=4em,nodes={anchor=center}]
{
a\1{A} & b\1{A}_{2}^{p} & ab\1{C} & \\
};
\draw [->] (m-1-1) -- (m-1-2);
\draw [->] (m-1-2) -- (m-1-3);
\end{tikzpicture}
\par}
%example 2
\par{\centering
\begin{tikzpicture}
\matrix (m) [matrix of math nodes, nodes in empty cells, row
sep=1em,column sep=2em,minimum width=4em,nodes={anchor=center}]
{
t\1{S}_{A}^{D} & s\1{R}_{CR} & t\1{S}_{CR} & \\
};
\draw [->] (m-1-1) -- (m-1-2);
\draw [->] (m-1-2) -- (m-1-3);
\end{tikzpicture}
\par}
\end{document}
Here is the output

How can add space in this plot ? I am a beginner in R

Here is the code for plotting 10 different graphs
lab=unique(train_train$PdDistrict)
lab=as.character(lab)
par(mfrow=c(5,2))
for(i in 1:length(lab))
{
a=plot(table(train_train[train_train$PdDistrict==lab[i],1]),las=3,main=lab[i])
}
The resultant graph is shown in this image link
How can i space those graphs so that its readable ?
My new code that I modified
lab=unique(train_train$PdDistrict)
lab=as.character(lab)
par(mfrow=c(1,2),mar=c(9,4,1,0))
for(i in 1:length(lab))
{
a=plot(table(train_train[train_train$PdDistrict==lab[i],1]),las=2,main=lab[i])
}
Now it looks much better.

Scilab : add legend for surface plot

I would like to add a legend to a surface plot.
I have tried, doing like this :
X=[0:0.3:2*%pi]; //example data
[x,y]=ndgrid(X,X);
z1=sin(X')*cos(X);
z2=z1/2;
z3=z1/3;
figure=scf();
surf(x,y,z1);
surf(x,y,z2);
surf(x,y,z3);
axes=figure.children(1);
axes.children(1).foreground=color(0,0,0);
axes.children(2).foreground=color(0,0,0);
axes.children(3).foreground=color(255,0,0);
axes.children(1).color_flag=0;
axes.children(2).color_flag=0;
axes.children(3).color_flag=0;
axes.children(1).color_mode=color(0,255,0);
axes.children(2).color_mode=color(0,0,255);
axes.children(3).color_mode=0;
legend(['z1','z1 divided by 2','z1 divided by 3'],opt=2,font_size=2);
I get the following error message:
!--error 10000
legend : Neither handle of type 'Polyline' can be found.
If it's not possible to do this with the basic version of Scilab, could you please advise to me some libraries Scilab permitting to do this.
Thanks for your help.
Legend not possible for surface plots
Legends is only for plot2dx graphs as stated in the documentation of legend properties:
This entity defines the parameters for legends drawn below plot2dx
graphs or created by the captions function.
Alternatives
You could simply add a title using xtitle
xtitle('z1,z1 div by2, z2 div by 3');
You could draw a box using uicontrol and style it using uicontrol_properties:
fig = gcf();
uicontrol(fig, "style", "text", ...
"string", "<html>z1<br>z1/2<br>z1/3</html>", ...
"position",[100 100 100 100], ...
"fontsize",15);

Resources