I have to draw a lot of graphs with a lot of edges. Some of the nodes are connected via edges in one direction, some in both. Edges that come from specific nodes are painted red, while the edges going into these nodes are painted black. Now I have two thinks I'd like to change to make the graphs more easy to understand:
- If two nodes are connected in both ways change the two arrows
<--
and-->
into one<-->
(the differences are small but they bug me). - If two nodes are connected in both ways, and one is one with the outgoing nodes in red automaticaly draw two arrows, either slightly bend or shifted, one in black one in red.
Its important, that this is done automaticaly, so that the results look always the same, independent from the slope of the connection. Here is my current code with the result:
\documentclass[preview]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary {positioning}
\usetikzlibrary{arrows,automata,shapes}
\usetikzlibrary{trees,fit,decorations.pathreplacing}
\usetikzlibrary{calc}
\usetikzlibrary{graphs}
\tikzset{near start abs/.style={xshift=1cm}}
\begin{document}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
Graph type one:
\begin{figure}[H]
\centering
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,semithick]
\tikzstyle{every state}=[scale =1,fill=blue,draw=none,text=white]
\def \n {12}
\def \radius {4cm}
\def \labelrad {4.7cm}
\def \margin {8} % margin in angles, depends on the radius
\foreach \s in {0,...,11}
{
\node[draw, state] (\s) at ({-360/\n * (\s +4.5)}:\radius) {$\s$};
% \draw[->, >=latex] ({360/\n * (\s - 1)+\margin}:\radius)
% arc ({360/\n * (\s - 1)+\margin}:{360/\n * (\s)-\margin}:\radius);
}
\node[fit=(0)(1)(2)(3)](input){};
\node[fit=(4)(5)](output){};
\node[fit=(6)(7)(8)(9)](intern){};
\node[fit=(10)(11)](inhib){};
% edges
\path
(0) edge (9)
edge (11)
(1) edge (8)
edge (9)
edge (10)
edge (11)
(2) edge (6)
edge (7)
edge (8)
edge (9)
(3) edge (9)
edge (11)
(4) edge (7)
edge (9)
edge (11)
(5) edge (6)
edge (9)
edge (10)
(6) edge (4)
edge (8)
edge (9)
edge (11)
(7) edge (4)
edge (5)
edge [red,dashed,bend left =50] node {} (9)
edge (11)
(8) edge (4)
edge (6)
edge (11)
(9) edge (4)
edge (7)
edge (10)
(10) edge[red] (5)
edge[red] (9)
(11) edge[red] (4)
edge[red] (5)
edge[red] (6)
;
% Input area
\begin{pgfonlayer}{background}
\filldraw [line width=4mm,join=round,black!10]
(input.north west) rectangle (input.south east);
\end{pgfonlayer}
% Input area
\begin{pgfonlayer}{background}
\filldraw [line width=4mm,join=round,blue!10]
(output.north west) rectangle (output.south east);
\end{pgfonlayer}
% Intern area
\begin{pgfonlayer}{background}
\filldraw [line width=4mm,join=round,green!10]
(intern.north west |- intern.north) rectangle (intern.south east |- intern.south);
\end{pgfonlayer}
% Inhib area
\begin{pgfonlayer}{background}
\filldraw [line width=4mm,join=round,red!10]
(inhib.north west |- inhib.north) rectangle (inhib.south east |- inhib.south);
\end{pgfonlayer}
% captions
% \node[below=0.3cm] at (input.south) {Input};
% \node[above=0.3cm] at(intern.north) {Intern};
% \node[below=0.3cm] at (inhib.south) {Inhibitorisch};
% Labels
\foreach \c [count=\x from 0] in {0,2,2,0,0,0,0,1,2,1,1,2} %{{a,f},{b,o},{c,o},{d,b},{e,a},{f,r}}
{
\node (\x) at ({-360/\n * (\x +4.5)}:\labelrad) {\c};
}
\end{tikzpicture}
\end{figure}
Graph type two:
\begin{figure}[H]
\centering
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm,semithick]
\tikzstyle{every state}=[scale =1,fill=blue,draw=none,text=white]
\node[state] (4) {4};
\node[state] (7) [above right of=4] {7};
\node[state] (9) [below right of=7] {9};
\node[state] (10)[below left of=9] {10};
% edges
\path
(4) edge (7)
edge (9)
(7) edge (4)
edge [red,dashed,bend left =50] node {} (9)
(9) edge (4)
edge (7)
edge (10)
(10) edge[red] (9)
;
% Labels
\node (l4) at ($(4)+(-.5,.7)$) {$(0,0\rightarrow2)$};
\node (l7) at ($(7)+(-0,.7)$) {$(2,1\rightarrow2)$};
\node (l9) at ($(9)+(.5,-.8)$) {$(4,1\rightarrow2)$};
\node (l10) at ($(10)+(0,-.7)$) {$(2,1\rightarrow2)$};
\node[red] (gew) at ($(7)!0.5!(9)+(1.3,.7)$) {$(0\rightarrow1)$};
\end{tikzpicture}
\end{figure}
\end{document}
With the result:
EDIT: Just ignore the dashed edge from node 7 to node 9 that is a different thing.
pstricks
has anything like this, but the TikZ graphing stuff seems the best bet to me.