我正在尝试用四张 png 图片组装一张图

我正在尝试用四张 png 图片组装一张图

我想将以下四张图片组合成一个2x2矩阵(先填充行):

在此处输入图片描述

在此处输入图片描述 在此处输入图片描述 在此处输入图片描述

是否可以将字母 AD 放在每个图形的左下角以标记它们?谢谢!我正在学习 Latex 图形。如果我可以将其保存为 pdf,那么我可以轻松使用“图形”来创建带有标题的最终图像。

图片1:

    \documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{all_men.csv}
a,b
1.431363764,0.880475418
1.505149978,0.984842271
1.568201724,1.182782759
1.62324929,1.426034556
1.672097858,1.764098403
1.716003344,2.109656911
1.755874856,2.37117351
1.792391689,2.609995129
1.826074803,2.827907138
1.857332496,3.008590765
\end{filecontents*}

\begin{filecontents*}{steps_men.csv}
a,b
1.431363764,0.880475418
1.431363764,0.984842271
1.505149978,0.984842271
1.505149978,1.182782759
1.568201724,1.182782759
1.568201724,1.426034556
1.62324929,1.426034556
1.62324929,1.764098403
1.672097858,1.764098403
1.672097858,2.109656911
1.716003344,2.109656911
1.716003344,2.37117351
1.755874856,2.37117351
1.755874856,2.609995129
1.792391689,2.609995129
1.792391689,2.827907138
1.826074803,2.827907138
1.826074803,3.008590765
1.857332496,3.008590765
\end{filecontents*}

\begin{document}
\pgfplotstableread[col sep=comma]{steps_men.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
    title={Men},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={0.880475418,0.984842271,1.182782759,1.426034556,1.764098403,2.109656911,
    2.37117351,2.609995129,2.827907138,3.008590765},
    yticklabels={8,10,15,27,58,129,235,407,673,1020},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\datatable};
\pgfplotstableread[col sep=comma]{all_men.csv}\datatable
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\datatable};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x 
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{axis}
\end{tikzpicture}
\hspace{0.10cm}
\end{document}

图片2:

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{all_women.csv}
a,b
1.431363764,0.769618098
1.505149978,1.001975048
1.568201724,1.321239024
1.62324929,1.599722199
1.672097858,1.874640705
1.716003344,2.13993154
1.755874856,2.338819817
1.792391689,2.520699054
1.826074803,2.692504537
1.857332496,2.851417046
\end{filecontents*}

\begin{filecontents*}{steps_women.csv}
a,b
1.431363764,0.769618098
1.431363764,1.001975048
1.505149978,1.001975048
1.505149978,1.321239024
1.568201724,1.321239024
1.568201724,1.599722199
1.62324929,1.599722199
1.62324929,1.874640705
1.672097858,1.874640705
1.672097858,2.13993154
1.716003344,2.13993154
1.716003344,2.338819817
1.755874856,2.338819817
1.755874856,2.520699054
1.792391689,2.520699054
1.792391689,2.692504537
1.826074803,2.692504537
1.826074803,2.851417046
1.857332496,2.851417046
\end{filecontents*}

\begin{document}
\pgfplotstableread[col sep=comma]{steps_women.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
    title={Women},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={0.769618098,1.001975048,1.321239024,1.599722199,1.874640705,2.13993154,2.338819817,2.520699054,
    2.692504537,2.851417046},
    yticklabels={6,10,21,40,75,138,218,332,493,710},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\datatable};
\pgfplotstableread[col sep=comma]{all_women.csv}\datatable
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\datatable};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x 
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{axis}
\end{tikzpicture}
\hspace{0.10cm}
\end{document}

图片3:

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{all_women.csv}
a,b
1.431363764,-0.114988484
1.505149978,0.303005044
1.568201724,0.806163983
1.62324929,1.109635968
1.672097858,1.24886644
1.716003344,1.50350828
1.755874856,1.621079988
1.792391689,1.714388602
1.826074803,1.830499259
1.857332496,1.888497767
\end{filecontents*}

\begin{filecontents*}{select_women.csv}
a,b
1.431363764,-0.114988484
1.505149978,0.303005044
1.568201724,0.806163983
1.62324929,1.109635968
\end{filecontents*}

\begin{filecontents*}{steps_women.csv}
a,b
1.431363764,-0.114988484
1.431363764,0.303005044
1.505149978,0.303005044
1.505149978,0.806163983
1.568201724,0.806163983
1.568201724,1.109635968
1.62324929,1.109635968
1.62324929,1.24886644
1.672097858,1.24886644
1.672097858,1.50350828
1.716003344,1.50350828
1.716003344,1.621079988
1.755874856,1.621079988
1.755874856,1.714388602
1.792391689,1.714388602
1.792391689,1.830499259
1.826074803,1.830499259
1.826074803,1.888497767
1.857332496,1.888497767
\end{filecontents*}

\begin{document}
\pgfplotstableread[col sep=comma]{steps_women.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
    title={Breast},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={-0.114988484,0.303005044,0.806163983,1.109635968,1.24886644,1.50350828,1.621079988,1.714388602,1.830499259,1.888497767},
    yticklabels={1,2,6,13,18,32,42,52,68,77},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\datatable};
\pgfplotstableread[col sep=comma]{select_women.csv}\datatable
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\datatable};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x 
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{axis}
\end{tikzpicture}
\hspace{0.10cm}
\end{document}

图片4:

\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepackage{filecontents}
\begin{filecontents*}{all_women.csv}
a,b
1.431363764,-0.467171002
1.505149978,-0.456662801
1.568201724,0.056784475
1.62324929,0.200868848
1.672097858,0.652092045
1.716003344,0.906600123
1.755874856,1.095174788
1.792391689,1.32472112
1.826074803,1.427429728
1.857332496,1.6849476
\end{filecontents*}

\begin{filecontents*}{steps_women.csv}
a,b
1.431363764,-0.467171002
1.431363764,-0.456662801
1.505149978,-0.456662801
1.505149978,0.056784475
1.568201724,0.056784475
1.568201724,0.200868848
1.62324929,0.200868848
1.62324929,0.652092045
1.672097858,0.652092045
1.672097858,0.906600123
1.716003344,0.906600123
1.716003344,1.095174788
1.755874856,1.095174788
1.755874856,1.32472112
1.792391689,1.32472112
1.792391689,1.427429728
1.826074803,1.427429728
1.826074803,1.6849476
1.857332496,1.6849476
\end{filecontents*}

\begin{document}
\pgfplotstableread[col sep=comma]{steps_women.csv}\datatable
\begin{tikzpicture}
\begin{axis}[
    title={Colon (Women)},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={-0.467171002,0.056784475,0.200868848,0.652092045,0.906600123,1.095174788,1.32472112,1.427429728,1.6849476},
    yticklabels={0,1,2,4,8,12,21,27,48},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\datatable};
\pgfplotstableread[col sep=comma]{all_women.csv}\datatable
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\datatable};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x 
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{axis}
\end{tikzpicture}
\hspace{0.10cm}
\end{document}

编辑:

\documentclass[12pt,a4paper,twoside]{report}
\usepackage{graphicx}
\usepackage{caption,subcaption}
\usepackage[margin=0.5in]{geometry}

\begin{document}
  \begin{figure}[htb]
  \captionsetup[subfigure]{singlelinecheck=off,labelfont={bf}}
  \renewcommand\thesubfigure{\Alph{subfigure}}
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{Figure2a}
      \caption{}
    \end{subfigure}%
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{Figure2b}
      \caption{}
    \end{subfigure}

    \vspace{1cm}
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{Figure2c}
      \caption{}
    \end{subfigure}%
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{Figure2d}
      \caption{}
    \end{subfigure}
  \end{figure}
\end{document}

这使:

在此处输入图片描述

是否有可能将“每 100,000 人的费率”下的字母对齐?

答案1

至少有两种方法可以做到这一点。首先使用subcaption及其subfigure环境,然后使用 的groupplotspgfplots。首先使用grouplots

\documentclass[border=5]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{width=10cm,compat=1.9}
\usepgfplotslibrary{groupplots}


\begin{document}
\pgfplotstableread[col sep=comma]{steps_men.csv}\men
\pgfplotstableread[col sep=comma]{steps_women.csv}\women
\pgfplotstableread[col sep=comma]{all_men.csv}\menall
\pgfplotstableread[col sep=comma]{all_women.csv}\womenall
\pgfplotstableread[col sep=comma]{select_women.csv}\selectwomen
\begin{tikzpicture}
\begin{groupplot}[
            group style={
                group name=my plots,
                group size=2 by 2,
                vertical sep=3cm,
                horizontal sep=3cm,
            },
            width=\linewidth,
        ]
\nextgroupplot[
    title={Men},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={0.880475418,0.984842271,1.182782759,1.426034556,1.764098403,2.109656911,
    2.37117351,2.609995129,2.827907138,3.008590765},
    yticklabels={8,10,15,27,58,129,235,407,673,1020},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\men};
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\menall};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
%
\nextgroupplot[
    title={Women},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={0.769618098,1.001975048,1.321239024,1.599722199,1.874640705,2.13993154,2.338819817,2.520699054,
    2.692504537,2.851417046},
    yticklabels={6,10,21,40,75,138,218,332,493,710},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\women};
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\womenall};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}

\nextgroupplot[
    title={Breast},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={-0.114988484,0.303005044,0.806163983,1.109635968,1.24886644,1.50350828,1.621079988,1.714388602,1.830499259,1.888497767},
    yticklabels={1,2,6,13,18,32,42,52,68,77},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\women};
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\selectwomen};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
%
\nextgroupplot[
    title={Colon (Women)},
    xlabel={Age (years)},
    ylabel={Rates per 100 000},
     legend pos=north west,
    ymajorgrids=true,
    grid style=dashed,
    xtick={1.431363764,1.505149978,1.568201724,1.62324929,
    1.672097858,1.716003344,1.755874856,1.792391689,1.826074803,1.857332496},
    xticklabels={[25-29],[30-34],[35-39],[40-44],[45-49],[50-54],[55-59],[60-64],[65-69],[70-75]},
    ytick={-0.467171002,0.056784475,0.200868848,0.652092045,0.906600123,1.095174788,1.32472112,1.427429728,1.6849476},
    yticklabels={0,1,2,4,8,12,21,27,48},
    x tick label style={rotate=60, anchor=east}
]
\addplot[blue] table [x=a,y=b, col sep=comma]{\women};
\pgfplotstableread[col sep=comma]{all_women.csv}\womenall
\addplot[red] table[
    y={create col/linear regression={y=b}}
]{\womenall};
\addlegendentry{Data}
\addlegendentry{%
$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
\pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$}
\end{groupplot}
%% add labels using tikz.
\node[font=\bfseries,scale=3] at ([shift={(-1.5cm,-1.1cm)}]my plots c1r1.south west) {A.};
\node[font=\bfseries,scale=3] at ([shift={(-1.5cm,-1.1cm)}]my plots c2r1.south west) {B.};
\node[font=\bfseries,scale=3] at ([shift={(-1.5cm,-1.1cm)}]my plots c1r2.south west) {C.};
\node[font=\bfseries,scale=3] at ([shift={(-1.5cm,-1.1cm)}]my plots c2r2.south west) {D.};
\end{tikzpicture}
\end{document}

在此处输入图片描述

使用您的数据,因为我的数据非常原始,因此图表不是您想要的。

subfigure上面看subcaption,它看起来像这样:

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption,subcaption}

\begin{document}
  \begin{figure}[htb]
  \captionsetup[subfigure]{singlelinecheck=off,labelfont={bf,Large}}
  \renewcommand\thesubfigure{\Alph{subfigure}}
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{example-image-a}
      \caption{}
    \end{subfigure}%
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{example-image-b}
      \caption{}
    \end{subfigure}

    \vspace{1cm}
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{example-image-c}
      \caption{}
    \end{subfigure}%
    \begin{subfigure}{0.5\linewidth}
      \centering
      \includegraphics[width=0.8\linewidth]{example-image}
      \caption{}
    \end{subfigure}
  \end{figure}
\end{document}

在此处输入图片描述

相关内容