我正在尝试绘制一个有向弧的图形。将会有相当多的弧,所以我需要以各种方式弯曲它们,以使图表清晰易读。
以下是我目前所掌握的信息:
\begin{tikzpicture}
\filldraw [pattern=north east lines] (0,0) circle (0.333) node (h1);
\fill [blue, opacity=0.33] (1.5,1.5) circle (0.333);
\draw (1.5,1.5) circle (0.333) node (1_1) { 1:1 };
\fill [green, opacity=0.33] (1.5,0) circle (0.333);
\draw (1.5,0) circle (0.333) node (2_1) { 2:1 };
\fill [red, opacity=0.33] (1.5,-1.5) circle (0.333);
\draw (1.5,-1.5) circle (0.333) node (3_1) { 3:1 };
\filldraw [pattern=north east lines] (3,0) circle (0.333) node (h2);
\fill [orange, opacity=0.33] (4.5,0.75) circle (0.333);
\draw (4.5,0.75) circle (0.333) node (4_1) { 4:1 };
\fill [orange, opacity=0.33] (6,0.75) circle (0.333);
\draw (6,0.75) circle (0.333) node (4_2) { 4:2 };
\fill [purple, opacity=0.33] (4.5,-0.75) circle (0.333);
\draw (4.5,-0.75) circle (0.333) node (5_1) { 5:1 };
\fill [purple, opacity=0.33] (6,-0.75) circle (0.333);
\draw (6,-0.75) circle (0.333) node (5_2) { 5:2 };
\filldraw [pattern=north east lines] (7.5,0) circle (0.333) node (h3);
\fill [teal, opacity=0.33] (9,0.75) circle (0.333);
\draw (9,0.75) circle (0.333) node (6_1) { 6:1 };
\fill [teal, opacity=0.33] (10.5,0.75) circle (0.333);
\draw (10.5,0.75) circle (0.333) node (6_2) { 6:2 };
\fill [olive, opacity=0.33] (9.75,-0.75) circle (0.333);
\draw (9.75,-0.75) circle (0.333) node (7_1) { 7:1 };
\filldraw [pattern=north east lines] (12,0) circle (0.333) node (h4);
\filldraw [pattern=north east lines] (13.5,0) circle (0.333) node (h5);
\draw [->] (0.333,-2.5) -- (13.3335,-2.5) node [midway, below] {Time};
\path [line, ->] (h1) edge [bend left=15] (1_1);
\path [line, ->] (h1) edge (2_1);
\path [line, ->] (h1) edge [bend right=15] (3_1);
\path [line, ->] (1_1) edge [bend left=15] (h2);
\path [line, ->] (2_1) edge (h2);
\path [line, ->] (3_1) edge [bend right=15] (h2);
\path [line, ->] (h2) -- (4_1);
\path [line, ->] (h2) -- (5_1);
\path [line, ->] (4_1) -- (4_2);
\path [line, ->] (5_1) -- (5_2);
\path [line, ->] (4_2) -- (h3);
\path [line, ->] (5_2) -- (h3);
\path [line, ->] (h3) -- (6_1);
\path [line, ->] (h3) -- (7_1);
\path [line, ->] (6_1) -- (6_2);
\path [line, ->] (6_2) -- (h4);
\path [line, ->] (7_1) -- (h4);
\path [line, ->] (h4) -- (h5);
\path [line, --] (h1) edge [bend left] ++(1.5,2.5) -- (h2);
\end{tikzpicture}
生成结果:
有几件事我似乎无法解决:
- 定向弧似乎不从圆的边缘开始和结束。我本来想这样做,但
\path [line,->] (h1) -- (1_1);
结果却不一样,但我不知道该怎么做bend left
。此外,edge
似乎应该可以解决这个问题,尽管它实际上让情况变得更糟。 - 注意我的最后一行:
\path [line, --] (h1) edge [bend left] ++(1.5,2.5) -- (h2);
。我想连接(h1)
到(h2)
,但我希望线路在上面,(1_1)
这样就不会太拥挤。出于某种原因,线路没有到达(h2)
。我试过了bend left=200
,但这只会让它看起来很奇怪。此外,箭头与图中的其他箭头不同。我不确定为什么会有箭头,因为->
那条线上根本没有箭头。
答案1
我认为您正试图从图案圆圈开始/结束箭头。您正在执行的这两个步骤可以通过定义节点来完成,例如
mynode/.style={pattern=north east lines, circle, draw,inner sep=2pt,outer sep=0pt},
并将phantom{1:1}
其作为参数,使得圆的大小相同。
另一方面,对于其他节点,您需要填充圆形区域并绘制圆形,然后放置节点,使其成为一个三步过程。您使用的三行代码可以只有一行,如下所示:
\node[myothernode,fill=orange!30] at (4.5,0.75) (4₁) { 4:1 };
其中myothernode
定义如下
myothernode/.style = {draw,circle,inner sep=2pt,outer sep=0pt}
现在所有的圆圈都是由
\node [mynode] at (0,0) (h1){\phantom{1:1}};
\node[myothernode,fill=blue!30] at (1.5,1.5) (1₁) { 1:1 };
\node[myothernode,fill=green!30] at (1.5,0) (2₁) { 2:1 };
\node[myothernode,fill=red!30] at (1.5,-1.5) (3₁) { 3:1 };
\node [mynode] at (3,0) (h2){\phantom{1:1}};
\node[myothernode,fill=orange!30] at (4.5,0.75) (4₁) { 4:1 };
\node[myothernode,fill=orange!30] at (6,0.75) (4₂) { 4:2 };
\node[myothernode,fill=purple!30] at (4.5,-0.75) (5₁) { 5:1 };
\node[myothernode,fill=purple!30] at (6,-0.75) (5₂) { 5:2 };
\node [mynode] at (7.5,0) (h3){\phantom{1:1}};
\node[myothernode,fill=teal!30] at (9,0.75) (6₁) { 6:1 };
\node[myothernode,fill=teal!30] at (10.5,0.75) (6₂) { 6:2 };
\node[myothernode,fill=olive!30] at (9.75,-0.75) (7₁) { 7:1 };
\node [mynode] at (12,0) (h4){\phantom{1:1}};
\node [mynode] at (13.5,0) (h5){\phantom{1:1}};
现在,绘制边缘的代码可以进一步简化。您使用的是 `\path[line,->],这会产生错误的结果。继续,您所说的弧/曲线可以通过几种方式绘制。其中一种是定义一个控制点,例如
(h1.north) edge [controls=+(80:2.5) and +(100:2.5)](h2.north);
您可以改变角度和距离来满足您的需要。
完整代码如下
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{patterns,arrows}
\tikzset{line/.style={-latex'},
mynode/.style={pattern=north east lines, circle, draw,inner sep=2pt,outer sep=0pt},
myothernode/.style = {draw,circle,inner sep=2pt,outer sep=0pt}
}
\begin{document}
\begin{tikzpicture}
\node [mynode] at (0,0) (h1){\phantom{1:1}};
\node[myothernode,fill=blue!30] at (1.5,1.5) (1₁) { 1:1 };
\node[myothernode,fill=green!30] at (1.5,0) (2₁) { 2:1 };
\node[myothernode,fill=red!30] at (1.5,-1.5) (3₁) { 3:1 };
\node [mynode] at (3,0) (h2){\phantom{1:1}};
\node[myothernode,fill=orange!30] at (4.5,0.75) (4₁) { 4:1 };
\node[myothernode,fill=orange!30] at (6,0.75) (4₂) { 4:2 };
\node[myothernode,fill=purple!30] at (4.5,-0.75) (5₁) { 5:1 };
\node[myothernode,fill=purple!30] at (6,-0.75) (5₂) { 5:2 };
\node [mynode] at (7.5,0) (h3){\phantom{1:1}};
\node[myothernode,fill=teal!30] at (9,0.75) (6₁) { 6:1 };
\node[myothernode,fill=teal!30] at (10.5,0.75) (6₂) { 6:2 };
\node[myothernode,fill=olive!30] at (9.75,-0.75) (7₁) { 7:1 };
\node [mynode] at (12,0) (h4){\phantom{1:1}};
\node [mynode] at (13.5,0) (h5){\phantom{1:1}};
\draw [->] (0.333,-2.5) -- (13.3335,-2.5) node [midway, below] {Time};
\path [line] (h1) edge [bend left=15] (1₁)
(h1) edge (2₁)
(h1) edge [bend right=15] (3₁)
(1₁) edge [bend left=15] (h2)
(2₁) edge (h2)
(3₁) edge [bend right=15] (h2)
(h2) edge (4₁)
(h2) edge (5₁)
(4₁) edge (4₂)
(5₁) edge (5₂)
(4₂) edge (h3)
(5₂) edge (h3)
(h3) edge (6₁)
(h3) edge (7₁)
(6₁) edge (6₂)
(6₂) edge (h4)
(7₁) edge (h4)
(h4) edge (h5)
(h1.north) edge [controls=+(80:2.5) and +(100:2.5)](h2.north); %% change control point: angle:<vertical distance>
\end{tikzpicture}
\end{document}