为多个子标题图添加一个图例

为多个子标题图添加一个图例

在此处输入图片描述我有以下问题:

我在一张图中有几个 pgf 图(见屏幕截图)。我用 \subcaptionbox 制作。现在我想为所有 6 个图添加一个图例,因为所有图中的信号都相同。它应该放在标题“图 3.8:每个路径上的频率扫描”上。有人能帮我怎么做吗?我已经看过这个帖子了如何为多个图添加一个图例条目?但我更希望不必重写我的整个情节。

\begin{figure}[htbp]
 \centering
  \subcaptionbox{300pF\label{fig:300pF}}
     {\input{sweep_300pF.tex}}
  \subcaptionbox{47pF\label{fig:47pF}}
     {\input{sweep_47pF.tex}}\\[30pt]
  \subcaptionbox{20pF\label{fig:20pF}}
     {\input{sweep_20pF.tex}}
  \subcaptionbox{6.2pF\label{fig:6.2pF}}
     {\input{sweep_6.2pF.tex}}\\[30pt]
  \subcaptionbox{2.7pF\label{fig:2.7pF}}
     {\input{sweep_2.7pF.tex}}
  \subcaptionbox{1.0pF\label{fig:1.0pF}}
     {\input{sweep_1.0pF.tex}}
  \caption{Frequency sweeps over each path}
   \label{fig:single_paths}
 \end{figure} 

这里是 pgf 图的示例代码:

\begin{tikzpicture}
   \begin{axis}[
     width=0.475\textwidth, height=6cm,    
     grid = major,
     grid style={dashed, gray!30},
     xmin=0,     % start the diagram at this x-coordinate
     xmax=4,    % end   the diagram at this x-coordinate
     ymin=-3,     % start the diagram at this y-coordinate
     ymax= 3,   % end   the diagram at this y-coordinate
     ytick={-3, -2, -1, 0, 1, 2, 3},
     axis background/.style={fill=white},
     ylabel=Voltage {[}V{]},
     xlabel=Frequency {[}MHz{]},
     tick align=outside]
      \addplot [color = blue]   table[y index = 1]{IMG/sweep_300pF.txt};
      \addplot [color = red]    table[y index = 2]{IMG/sweep_300pF.txt};
      \addplot [color = green]  table[y index =3]{IMG/sweep_300pF.txt};                  
     \end{axis}
   \end{tikzpicture}

相关内容