如何使不同大小的子图形看起来匹配

如何使不同大小的子图形看起来匹配

我还有一个有关 tkzpictures 的问题。

目前我的身材是这样的:

在此处输入图片描述

它是在以下代码的帮助下生成的pgfplots:两个 y 轴,带有三个图和一个图例

\begin{figure}[ht]
     \begin{center}
        \subfigure[1]{
            \begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}
\pgfplotsset{
    scale only axis,
      x tick label style={/pgf/number format/1000 sep=},
      xtick=data
}
\begin{axis}[width=\textwidth, height=8cm, ybar stacked,
  axis y line*=right,
  ymin=0, ymax=100,
  xlabel=Year,
  ylabel=Percentage,
  xtick=data
]
\addplot[gray, fill=gray]
  coordinates{
    (1973,  62.7)
    (1978,  58.4)
    (1983,  55.7)
    (1988,  56.1)
    (1993,  55)
    (1998,  56.4)
    (2003,  54.4)
    (2008,  54.3)
    (2013,  53.9)
}; \label{a}
\addlegendentry{A}
\addplot[lightgray, fill=lightgray]
  coordinates{
    (1973,  37.3)
    (1978,  41.6)
    (1983,  42.8)
    (1988,  43.9)
    (1993,  45)
    (1998,  43.6)
    (2003,  45.6)
    (2008,  45.7)
    (2013,  46.1)
}; \label{b}
\addlegendentry{B}
\end{axis}
\begin{axis}[width=\textwidth, height=8cm,
  axis y line*=left,
  axis x line=none,
  ymin=50, ymax=130, 
  xtick=data,
  ylabel=Euro, ymajorgrids
]
\addlegendimage{/pgfplots/refstyle=a}\addlegendentry{A}
\addlegendimage{/pgfplots/refstyle=b}\addlegendentry{B}
\addplot[smooth, mark=*, blue]
  coordinates{
    (1973,  66)
    (1998,  70.8)
    (2003,  72.4)
    (2008,  71.4)
    (2013,  71.5)
}; \addlegendentry{C}
\addplot[smooth, mark=*, cyan]
  coordinates{
    (1973,  101)
    (1998,  120.1)
    (2003,  121.9)
    (2008,  122.9)
    (2013,  123.9)
}; \addlegendentry{D}
\end{axis}
\end{tikzpicture}
\end{adjustbox}
            \label{fig:1}} \\
        \subfigure[2]{
        \begin{adjustbox}{width=0.47\textwidth}
           \begin{tikzpicture}
\pgfplotsset{
    scale only axis,
      x tick label style={/pgf/number format/1000 sep=}
}
\begin{axis}[width=\textwidth, ybar stacked,
  axis y line*=right,
  ymin=0, ymax=100, xmin=1992, xmax=2014,
  xlabel=Year,
  ylabel=Percentage,
  xtick={1993,1998,2003,2008,2013}
]
\addplot[gray, fill=gray]
  coordinates{
    (1993,  81) 
    (1998,  74.1)
    (2003,  68.3)
    (2008,  67.5)
    (2013,  68.6)
}; \label{a}
\addlegendentry{A}
\addplot[lightgray, fill=lightgray]
  coordinates{
        (1993,  19) 
    (1998,  25.9)
    (2003,  31.7)
    (2008,  32.5)
    (2013,  31.4)
}; \label{b}
\addlegendentry{B}
\end{axis}
\begin{axis}[width=\textwidth,
  axis y line*=left,
  axis x line=none,
  ymin=50, ymax=130, xmin=1992, xmax=2014,
  xtick={1993,1998,2003,2008,2013},
  ylabel=Euro,
  ymajorgrids, unbounded coords=jump
]
\addlegendimage{/pgfplots/refstyle=a}\addlegendentry{A}
\addlegendimage{/pgfplots/refstyle=b}\addlegendentry{B}
\addplot[smooth, mark=*, blue]
  coordinates{
  (1993,    nan)
    (1998,  60.7)
    (2003,  61.7)
    (2008,  62.4)
    (2013,  63.4)
}; \addlegendentry{C}
\addplot[smooth, mark=*, cyan]
  coordinates{
  (1993,    nan)
    (1998,  105.9)
    (2003,  109.9)
    (2008,  109.5)
    (2013,  110.7)
}; \addlegendentry{D}
\end{axis}
\end{tikzpicture}
\end{adjustbox}
           \label{fig:2}}  
        \subfigure[3]{
           \begin{adjustbox}{width=0.47\textwidth}
\begin{tikzpicture}
\pgfplotsset{
    scale only axis,
      x tick label style={/pgf/number format/1000 sep=}
}
\begin{axis}[width=\textwidth, ybar stacked,
  axis y line*=right,
  ymin=0, ymax=100, xmin=1992, xmax=2014,
  xlabel=Year,
  ylabel=Percentage,
  xtick={1993,1998,2003,2008,2013}
]
\addplot[gray, fill=gray]
  coordinates{
    (1993,  61) 
    (1998,  59.7)
    (2003,  57)
    (2008,  56.8)
    (2013,  57)
}; \label{a}
\addlegendentry{A}
\addplot[lightgray, fill=lightgray]
  coordinates{
        (1993,  39) 
    (1998,  40.3)
    (2003,  43)
    (2008,  43.2)
    (2013,  43)
}; \label{b}
\addlegendentry{B}
\end{axis}
\begin{axis}[width=\textwidth,
  axis y line*=left,
  axis x line=none,
  ymin=50, ymax=130, 
  xtick={1993,1998,2003,2008,2013}, xmin=1992, xmax=2014,
  ylabel=Euro,
  ymajorgrids, unbounded coords=jump
]
\addlegendimage{/pgfplots/refstyle=a}\addlegendentry{A}
\addlegendimage{/pgfplots/refstyle=b}\addlegendentry{B}
\addplot[smooth, mark=*, blue]
  coordinates{
    (1993,  nan)
    (1998,  68.3)
    (2003,  70.1)
    (2008,  69.4)
    (2013,  69.4)
}; \addlegendentry{C}
\addplot[smooth, mark=*, cyan]
  coordinates{
    (1993,  nan)
    (1998,  118.6)
    (2003,  120.1)
    (2008,  121)
    (2013,  121.9)
}; \addlegendentry{D}
\end{axis}
\end{tikzpicture}
\end{adjustbox}
           \label{fig:3}}
    \end{center}
\end{figure}

现在,我想在图例中为 A 和 B 添加条形,就像条形图通常的情况一样。此外,我想使子图 2 和 3 的条形更粗,并放大轴标题和数字的字体,以便下方子图更好地匹配上方子图。

谁能帮助我?提前谢谢!:)

答案1

由于我没有更多时间,所以只给其他人提供部分答案。

  • 我把一些常见的选项放在pgfplotsset
  • 所有字体和栏目现在都大小相同
  • 使用 向图例添加了条形条目\addlegendimage{empty legend}\addlegendentry{\ref{a} A},尽管它还不完善

结果

结果

平均能量损失

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\begin{figure}[ht]
     \begin{center}
%        \subfigure[1]{
%            \begin{adjustbox}{width=\textwidth}
\pgfplotsset{width=0.4\textwidth,
    scale only axis,
    x tick label style={/pgf/number format/1000 sep=},
    xtick=data
}
\begin{tikzpicture}
\begin{axis}[width=\textwidth, height=8cm, ybar stacked,
  axis y line*=right,
  ylabel near ticks, yticklabel pos=right,
  ymin=0, ymax=100,
  xlabel=Year,
  ylabel=Percentage,
]
\addplot[gray, fill=gray]
  coordinates{
    (1973,  62.7)
    (1978,  58.4)
    (1983,  55.7)
    (1988,  56.1)
    (1993,  55)
    (1998,  56.4)
    (2003,  54.4)
    (2008,  54.3)
    (2013,  53.9)
}; \label{a}
\addplot[lightgray, fill=lightgray]
  coordinates{
    (1973,  37.3)
    (1978,  41.6)
    (1983,  42.8)
    (1988,  43.9)
    (1993,  45)
    (1998,  43.6)
    (2003,  45.6)
    (2008,  45.7)
    (2013,  46.1)
}; \label{b}
\end{axis}
\begin{axis}[width=\textwidth, height=8cm, 
  axis y line*=left,
  axis x line=none,
  ymin=50, ymax=130, 
  ylabel=Euro, ymajorgrids
]
\addlegendimage{empty legend}\addlegendentry{\ref{a} A}
\addlegendimage{empty legend}\addlegendentry{\ref{b} B}
\addplot[smooth, mark=*, blue]
  coordinates{
    (1973,  66)
    (1998,  70.8)
    (2003,  72.4)
    (2008,  71.4)
    (2013,  71.5)
}; 
\addlegendentry{C}
\addplot[smooth, mark=*, cyan]
  coordinates{
    (1973,  101)
    (1998,  120.1)
    (2003,  121.9)
    (2008,  122.9)
    (2013,  123.9)
}; 
\addlegendentry{D}
\end{axis}
\end{tikzpicture}
%\end{adjustbox}
%            \label{fig:1}} \\
%        \subfigure[2]{
%        \begin{adjustbox}{width=0.47\textwidth}
\begin{tikzpicture}
\begin{axis}[
  ybar stacked,
  axis y line*=right,
  ylabel near ticks, yticklabel pos=right,
  ymin=0, ymax=100, xmin=1992, xmax=2014,
  xlabel=Year,
  ylabel=Percentage,
]
\addplot[gray, fill=gray]
  coordinates{
    (1993,  81) 
    (1998,  74.1)
    (2003,  68.3)
    (2008,  67.5)
    (2013,  68.6)
}; \label{a}
\addlegendentry{A}
\addplot[lightgray, fill=lightgray]
  coordinates{
        (1993,  19) 
    (1998,  25.9)
    (2003,  31.7)
    (2008,  32.5)
    (2013,  31.4)
}; \label{b}
\addlegendentry{B}
\end{axis}
\begin{axis}[
  axis y line*=left,
  axis x line=none,
  ymin=50, ymax=130, xmin=1992, xmax=2014,
  ylabel=Euro,
  ymajorgrids, unbounded coords=jump
]
\addlegendimage{/pgfplots/refstyle=a}\addlegendentry{A}
\addlegendimage{/pgfplots/refstyle=b}\addlegendentry{B}
\addplot[smooth, mark=*, blue]
  coordinates{
  (1993,    nan)
    (1998,  60.7)
    (2003,  61.7)
    (2008,  62.4)
    (2013,  63.4)
}; \addlegendentry{C}
\addplot[smooth, mark=*, cyan]
  coordinates{
  (1993,    nan)
    (1998,  105.9)
    (2003,  109.9)
    (2008,  109.5)
    (2013,  110.7)
}; \addlegendentry{D}
\end{axis}
\end{tikzpicture}
%\end{adjustbox}
%           \label{fig:2}}  
%        \subfigure[3]{
%           \begin{adjustbox}{width=0.47\textwidth}
\begin{tikzpicture}
\begin{axis}[ybar stacked,
  axis y line*=right,
  ylabel near ticks, yticklabel pos=right,
  ymin=0, ymax=100, xmin=1992, xmax=2014,
  xlabel=Year,
  ylabel=Percentage,
]
\addplot[gray, fill=gray]
  coordinates{
    (1993,  61) 
    (1998,  59.7)
    (2003,  57)
    (2008,  56.8)
    (2013,  57)
}; \label{a}
\addlegendentry{A}
\addplot[lightgray, fill=lightgray]
  coordinates{
        (1993,  39) 
    (1998,  40.3)
    (2003,  43)
    (2008,  43.2)
    (2013,  43)
}; \label{b}
\addlegendentry{B}
\end{axis}
\begin{axis}[
  axis y line*=left,
  axis x line=none,
  ymin=50, ymax=130, 
 xmin=1992, xmax=2014,
  ylabel=Euro,
  ymajorgrids, unbounded coords=jump
]
\addlegendimage{/pgfplots/refstyle=a}\addlegendentry{A}
\addlegendimage{/pgfplots/refstyle=b}\addlegendentry{B}
\addplot[smooth, mark=*, blue]
  coordinates{
    (1993,  nan)
    (1998,  68.3)
    (2003,  70.1)
    (2008,  69.4)
    (2013,  69.4)
}; \addlegendentry{C}
\addplot[smooth, mark=*, cyan]
  coordinates{
    (1993,  nan)
    (1998,  118.6)
    (2003,  120.1)
    (2008,  121)
    (2013,  121.9)
}; \addlegendentry{D}
\end{axis}
\end{tikzpicture}
%\end{adjustbox}
%           \label{fig:3}}
    \end{center}
\end{figure}
\end{document} 

相关内容