1

I have another question concerning tkzpictures.

Currently, my figure looks like this:

enter image description here

It was generated using the following code with the help of pgfplots: two y-axis with three plots and one legend

\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}

Now, I would like to have bars for A and B in the legend as it is normally the case with bars. Moreover, I would like to make the bars of subfigures 2 and 3 thicker and enlarge the fonts of the axis titles and numbers, so that the lower subfigures better match the upper one.

Who can help me? Thanks in advance! :)

Stefan Pinnow
  • 29,535
Newbeee
  • 179
  • 1
    I think you know the drill: don't provide a code fragment; instead, provide a Minimum Working Example that compiles. Don't make us guess as to which packages need to be loaded in order to get your code to compile. People here would rather tinker with compilable code that engage in guess work. – Mico Nov 29 '16 at 22:08

1 Answers1

3

Partial answer for others to complete as I don't have more time.

  • I placed some common options in pgfplotsset
  • All the fonts and bars are now the same size
  • Added bar entry to the legend using \addlegendimage{empty legend}\addlegendentry{\ref{a} A}, although it is not perfect yet

Result

Result

MWE

\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} 
Roald
  • 1,245