将 2x3 子图并排放置在 pgfplots 中

将 2x3 子图并排放置在 pgfplots 中

我需要将 3x2 子图并排放置,但无法想出解决方案。问题是,我曾经这样做过,我需要并排放置 2x1 图形,即两个图形并排放置。然而,在这里,我认为解决方案是在\hfill子图环境的底部添加一个,我已经为我的新图表尝试过,但不起作用。为了说明我的意思,我想要的是:

在此处输入图片描述

这样,每个子图“列”都是其自己的面板。我使用的代码如下:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{subcaption}


\begin{document}

\begin{figure}[!h] 
\caption{xx}
\label{x}
\captionsetup[subfigure]{justification=centering}
  \begin{subfigure}[b]{\columnwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=15,
            ymax=35,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={15, 20, 25, 30, 35},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=obscureblue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=EV/EBITDA,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}
\\[3ex]
 \begin{subfigure}[b]{\columnwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=15,
            ymax=35,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={15, 20, 25, 30, 35},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=obscureblue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=EV/EBIT,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)
    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)
    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}
\\[3ex]
 \begin{subfigure}[b]{\columnwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=20,
            ymax=50,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={20, 25, 30, 35, 40, 45,50},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=obscureblue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=P/E,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}
\hfill
\begin{subfigure}[b]{\columnwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=15,
            ymax=35,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={15, 20, 25, 30, 35},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=obscureblue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=EV/EBITDA,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}

\end{document}

为了避免代码过多,我仅提供了如“面板” A 所示的对齐的 3 个子图的代码。

答案1

像这样?

在此处输入图片描述

\documentclass{article}

\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{subcaption}
\usepackage{geometry}

\begin{document}

\begin{figure}[!h] 
\caption{xx}
\label{x}
\captionsetup[subfigure]{justification=centering}
\begin{minipage}{0.5\textwidth}
\centering Panel A: aaa
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering Panel B: bbbb
\end{minipage} 
\smallskip

  \begin{subfigure}[b]{0.5\textwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=15,
            ymax=35,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={15, 20, 25, 30, 35},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=blue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=EV/EBITDA,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}%
 \begin{subfigure}[b]{0.5\textwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=15,
            ymax=35,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={15, 20, 25, 30, 35},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=blue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=EV/EBIT,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)
    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)
    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}
\\[3ex]
 \begin{subfigure}[b]{0.5\textwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=20,
            ymax=50,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={20, 25, 30, 35, 40, 45,50},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=blue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=P/E,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}%
\begin{subfigure}[b]{0.5\textwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=15,
            ymax=35,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={15, 20, 25, 30, 35},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=blue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=EV/EBITDA,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}
\\[3ex]
 \begin{subfigure}[b]{0.5\textwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=20,
            ymax=50,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={20, 25, 30, 35, 40, 45,50},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=blue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=P/E,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}%
\begin{subfigure}[b]{0.5\textwidth}
\begin{tikzpicture}   
\begin{axis}[width=7cm,height=6cm,
            ylabel={Absolute Percentage Error},
            xmin=4,
            xmax=16,
            ymin=15,
            ymax=35,
            xtick=data,
            xticklabel style=
            {/pgf/number format/1000 sep=,rotate=40},
            ytick={15, 20, 25, 30, 35},
            axis background/.style={fill=gray!5},
            legend style={fill=gray!5},
            xtick pos=lower,ytick pos=left,
            yticklabel=\pgfkeys{/pgf/number format/.cd,fixed,precision=0,zerofill}\pgfmathprintnumber{\tick}\%,
             title style={yshift=-0.21cm,fill=blue,text
             width=5.2cm,text=white,font=\bfseries,align=center},
             title=EV/EBITDA,
]
\typeout{\pgfkeysvalueof{/pgfplots/width}}
            \addplot [semithick,mark=square*,black,mark options={scale=1.2}] coordinates {
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{SBP+SARD}}
\addplot[semithick,mark=*,red,mark options={scale=1.2}]
coordinates{
(4,20)
(6,20)
(8,20)
(10,20)
(12,20)
(14,20)
(16,20)

    };
\addlegendentry{\small{GICS+SARD}}    
\end{axis}
\end{tikzpicture}
\end{subfigure}
\end{figure}

\end{document}

相关内容