如何将 Tikz 图形和文本添加到任意 x 轴?

如何将 Tikz 图形和文本添加到任意 x 轴?

我希望我的论文中出现下图。 图片

问题是,虽然我知道如何绘制单个图表,但我不知道如何将它们放在 x 轴上(标题为“效率低下”),以及如何在轴下方添加标签。有人能帮我吗?我已经添加了下面图表的基本代码。

\tikzset{
peer/.style={draw,circle, left color=gray, text=black, minimum width=    {width("N-1")+2pt}},
superpeer/.style={draw, circle,  left color=gray, text=black, minimum width=2pt},
point/.style = {fill=black,inner sep=1pt, circle, minimum     width=3pt,align=right,rotate=60},
forward edge/.style={->, >=stealth, shorten >=0pt, thick, color=black},
}

\begin{figure}[htbp]

\centering
\begin{tikzpicture}[->,>=stealth', shorten>=1pt, auto, node distance=0.8cm, semithick]
  \node[peer] (A) {$0$};
  \node[peer]         (B)  at ($ (A) + (20:1.5) $) {$1$};
  \node[peer]         (C)  at ($ (A) + (-52:1.5) $) {$2$};
  \node[peer]         (D)   at ($ (A) + (-150:1.5) $){$3$};
  \node[point] (p1)  at ($ (A) + (-196:1.5) $){};
  \node[point] (p2)  at ($ (A) + (-206:1.6) $){};  
  \node[point] (p3)  at ($ (A) + (-216:1.5) $){};  
  \node[peer] (E) at ($ (A) + (92:1.5) $) {\footnotesize $N$-1};
  \path (B) edge [color=black, sloped] node[] {}(A);
  \path (C) edge [color=black, sloped] node[] {}(A);
  \path (D) edge [color=black, sloped] node[] {}(A);
  \path (E) edge [color=black, sloped, above] node[] {}(A);
\end{tikzpicture}
\end{figure}

答案1

一种可能性是:

在此处输入图片描述

这个想法是分别绘制每个图形并将它们框起来;然后在 a 中tikzpicture绘制轴并将框放置在\nodes 内的所需位置。这样,使用锚点等,您可以轻松控制图形相对于轴的位置。在我的示例代码中,我复制了其中一个图形来说明该过程,但在您的实际代码中,您使用 \myboxc 来绘制实际的第三个图形。

代码:

\documentclass[border=3pt]{standalone}
\usepackage{calc}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,arrows.meta,positioning}

\tikzset{
peer/.style={
  draw,
  circle,
  left color=gray,
  text=black, 
  minimum width={25pt}
  },
superpeer/.style={
  draw, 
  circle,  
  left color=gray, 
  text=black, 
  minimum width=2pt
  },
point/.style = {
  fill=black,
  inner sep=1pt, 
  circle, 
  minimum width=3pt,
  align=right,
  rotate=60
  },
forward edge/.style={->, >=stealth, shorten >=0pt, thick, color=black},
}

\newlength\FigWd
\setlength\FigWd{18cm}

\newsavebox\myboxa
\newsavebox\myboxb
\newsavebox\myboxc

\savebox\myboxa{%
\begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto, node distance=0.8cm, semithick]
%The leftmost graph
  \node[peer] (A) {$0$};
  \node[peer]         (B)  at ($ (A) + (20:1.5) $) {$1$};
  \node[peer]         (C)  at ($ (A) + (-52:1.5) $) {$2$};
  \node[peer]         (D)   at ($ (A) + (-150:1.5) $){$3$};
  \node[point] (p1)  at ($ (A) + (-196:1.5) $){};
  \node[point] (p2)  at ($ (A) + (-206:1.6) $){};  
  \node[point] (p3)  at ($ (A) + (-216:1.5) $){};  
  \node[peer] (E) at ($ (A) + (92:1.5) $) {\footnotesize $N$-1};
  \path (B) edge [color=black, sloped] node[] {}(A);
  \path (C) edge [color=black, sloped] node[] {}(A);
  \path (D) edge [color=black, sloped] node[] {}(A);
  \path (E) edge [color=black, sloped, above] node[] {}(A);
\end{tikzpicture}
}

\savebox\myboxb{%
\begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto, node distance=0.8cm, semithick]
%The middle graph
  \node[peer] (A) {$0$};
  \node[peer,right=of A] (B) {$1$};
  \node[peer,right=of B] (C) {$1$};
  \node[peer,right=of C] (D) {$1$};
  \node[peer,right=of D] (E) {$1$};
  \path (A) edge (B);
  \path (B) edge (C);
  \path (C) edge (D);
  \path (D) edge (E);
\end{tikzpicture}%
}

\savebox\myboxc{%
\begin{tikzpicture}[->,>=stealth', shorten >=1pt, auto, node distance=0.8cm, semithick]
%The rightmost graph
  \node[peer] (A) {$0$};
  \node[peer]         (B)  at ($ (A) + (20:1.5) $) {$1$};
  \node[peer]         (C)  at ($ (A) + (-52:1.5) $) {$2$};
  \node[peer]         (D)   at ($ (A) + (-150:1.5) $){$3$};
  \node[point] (p1)  at ($ (A) + (-196:1.5) $){};
  \node[point] (p2)  at ($ (A) + (-206:1.6) $){};  
  \node[point] (p3)  at ($ (A) + (-216:1.5) $){};  
  \node[peer] (E) at ($ (A) + (92:1.5) $) {\footnotesize $N$-1};
  \path (B) edge [color=black, sloped] node[] {}(A);
  \path (C) edge [color=black, sloped] node[] {}(A);
  \path (D) edge [color=black, sloped] node[] {}(A);
  \path (E) edge [color=black, sloped, above] node[] {}(A);
\end{tikzpicture}%
}

\begin{document}

\begin{tikzpicture}[>=stealth]
\coordinate (origin) at (0,0);
\coordinate (right) at (15cm,0);
\draw[*->] 
  (origin) -- (\FigWd,0) coordinate (right) node[anchor=west] {Inneficiency};
\draw[->] 
  ([yshift=-15pt]origin) -- node[below] {Increasing $\eta_i$} ++(0.5\FigWd-1cm,0);
\draw[->] 
  ([yshift=-15pt]right) -- node[below] {Increasing $\eta_j$} ++(-0.5\FigWd+1cm,0);
\node[anchor=south west] at (origin)
  {\usebox\myboxa};  
\node[anchor=south] at ( $ (origin)!0.5!(right) $ )
  {\usebox\myboxb};  
\node[anchor=south east] at (right)
  {\usebox\myboxc};  
\end{tikzpicture}

\end{document}

相关内容