我如何创建一个包含六个数字的图形?

我如何创建一个包含六个数字的图形?

所以我使用 Overleaf (Latex) 并制作了六个不同的独立折线图。但是,我希望每个折线图都在同一张图中,因此最终结果如下:

在此处输入图片描述

有人能帮帮我吗?这是我的(示例)代码:

    \documentclass[12pt]{article}
    \usepackage{graphicx}
    \usepackage{pgfplots}
    \usepackage{tikz}
    \usepackage{caption}
    \usepackage{subcaption}
    \usepackage{pgfplotstable}
    \pgfplotsset{compat=1.7}
    \usepackage[section]{placeins}
    \usepackage[labelfont=bf]{caption}
    \usepackage{siunitx}

\begin{figure}[!htb]
    \centering
\caption{Negative Campaigning in the Swedish Multi-Party System 1970-2022.}
\begin{tikzpicture}
\pgfplotsset{scale only axis,}
\begin{axis}[x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed}, yticklabel={$\pgfmathprintnumber{\tick}\%$}, grid=both, minor tick num=9, grid style={line width=.2pt, draw=black!10}, major grid style={line width=.4pt, draw=black!20}, enlargelimits={abs=0.1}, width=12cm, height=8cm, xmin=1970, xmax=2022, ymin=0, ymax=16, xlabel= \textbf{Time}, ylabel= \textbf{Degree of Negative Campaigning}, xtick={1970,1973,1976,1979,1982,1985,1988,1991,1994,1998,2002,2006,2010,2014,2018,2022}, every tick label/.append style={font=\tiny}]
\addplot[color=black, mark=*] 
coordinates{ 
(1970,13.6363658)
(1973,3.4666667)
(1976,9.4786733)
(1979,7.7683621)
(1982,14.6520151)
(1985,11.3144759)
(1988,1.8472911)
(1991,4.14201161)
(1994,5.5229145)
(1998,3.23846942)
(2002,4.75448152)
(2006,3.775099)
(2010,2.680462)
(2014,6.462614250) 
(2018,7.56129860) 
(2022,5.7528533)};
\addlegendentry{Election manifestos}
\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}[!htb]
    \centering
\caption{Negative Campaigning in the Swedish Multi-Party System 1970-2022.}
\begin{tikzpicture}
\pgfplotsset{scale only axis,}
\begin{axis}[x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed}, yticklabel={$\pgfmathprintnumber{\tick}\%$}, grid=both, minor tick num=9, grid style={line width=.2pt, draw=black!10}, major grid style={line width=.4pt, draw=black!20}, enlargelimits={abs=0.1}, width=12cm, height=8cm, xmin=1970, xmax=2022, ymin=0, ymax=16, xlabel= \textbf{Time}, ylabel= \textbf{Degree of Negative Campaigning}, xtick={1970,1973,1976,1979,1982,1985,1988,1991,1994,1998,2002,2006,2010,2014,2018,2022}, every tick label/.append style={font=\tiny}]
\addplot[color=black, mark=*] 
coordinates{ 
(1970,13.6363658)
(1973,3.4666667)
(1976,9.4786733)
(1979,7.7683621)
(1982,14.6520151)
(1985,11.3144759)
(1988,1.8472911)
(1991,4.14201161)
(1994,5.5229145)
(1998,3.23846942)
(2002,4.75448152)
(2006,3.775099)
(2010,2.680462)
(2014,6.462614250) 
(2018,7.56129860) 
(2022,5.7528533)};
\addlegendentry{Election manifestos}
\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}[!htb]
    \centering
\caption{Negative Campaigning in the Swedish Multi-Party System 1970-2022.}
\begin{tikzpicture}
\pgfplotsset{scale only axis,}
\begin{axis}[x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed}, yticklabel={$\pgfmathprintnumber{\tick}\%$}, grid=both, minor tick num=9, grid style={line width=.2pt, draw=black!10}, major grid style={line width=.4pt, draw=black!20}, enlargelimits={abs=0.1}, width=12cm, height=8cm, xmin=1970, xmax=2022, ymin=0, ymax=16, xlabel= \textbf{Time}, ylabel= \textbf{Degree of Negative Campaigning}, xtick={1970,1973,1976,1979,1982,1985,1988,1991,1994,1998,2002,2006,2010,2014,2018,2022}, every tick label/.append style={font=\tiny}]
\addplot[color=black, mark=*] 
coordinates{ 
(1970,13.6363658)
(1973,3.4666667)
(1976,9.4786733)
(1979,7.7683621)
(1982,14.6520151)
(1985,11.3144759)
(1988,1.8472911)
(1991,4.14201161)
(1994,5.5229145)
(1998,3.23846942)
(2002,4.75448152)
(2006,3.775099)
(2010,2.680462)
(2014,6.462614250) 
(2018,7.56129860) 
(2022,5.7528533)};
\addlegendentry{Election manifestos}
\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}[!htb]
    \centering
\caption{Negative Campaigning in the Swedish Multi-Party System 1970-2022.}
\begin{tikzpicture}
\pgfplotsset{scale only axis,}
\begin{axis}[x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed}, yticklabel={$\pgfmathprintnumber{\tick}\%$}, grid=both, minor tick num=9, grid style={line width=.2pt, draw=black!10}, major grid style={line width=.4pt, draw=black!20}, enlargelimits={abs=0.1}, width=12cm, height=8cm, xmin=1970, xmax=2022, ymin=0, ymax=16, xlabel= \textbf{Time}, ylabel= \textbf{Degree of Negative Campaigning}, xtick={1970,1973,1976,1979,1982,1985,1988,1991,1994,1998,2002,2006,2010,2014,2018,2022}, every tick label/.append style={font=\tiny}]
\addplot[color=black, mark=*] 
coordinates{ 
(1970,13.6363658)
(1973,3.4666667)
(1976,9.4786733)
(1979,7.7683621)
(1982,14.6520151)
(1985,11.3144759)
(1988,1.8472911)
(1991,4.14201161)
(1994,5.5229145)
(1998,3.23846942)
(2002,4.75448152)
(2006,3.775099)
(2010,2.680462)
(2014,6.462614250) 
(2018,7.56129860) 
(2022,5.7528533)};
\addlegendentry{Election manifestos}
\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}[!htb]
    \centering
\caption{Negative Campaigning in the Swedish Multi-Party System 1970-2022.}
\begin{tikzpicture}
\pgfplotsset{scale only axis,}
\begin{axis}[x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed}, yticklabel={$\pgfmathprintnumber{\tick}\%$}, grid=both, minor tick num=9, grid style={line width=.2pt, draw=black!10}, major grid style={line width=.4pt, draw=black!20}, enlargelimits={abs=0.1}, width=12cm, height=8cm, xmin=1970, xmax=2022, ymin=0, ymax=16, xlabel= \textbf{Time}, ylabel= \textbf{Degree of Negative Campaigning}, xtick={1970,1973,1976,1979,1982,1985,1988,1991,1994,1998,2002,2006,2010,2014,2018,2022}, every tick label/.append style={font=\tiny}]
\addplot[color=black, mark=*] 
coordinates{ 
(1970,13.6363658)
(1973,3.4666667)
(1976,9.4786733)
(1979,7.7683621)
(1982,14.6520151)
(1985,11.3144759)
(1988,1.8472911)
(1991,4.14201161)
(1994,5.5229145)
(1998,3.23846942)
(2002,4.75448152)
(2006,3.775099)
(2010,2.680462)
(2014,6.462614250) 
(2018,7.56129860) 
(2022,5.7528533)};
\addlegendentry{Election manifestos}
\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}[!htb]
    \centering
\caption{Negative Campaigning in the Swedish Multi-Party System 1970-2022.}
\begin{tikzpicture}
\pgfplotsset{scale only axis,}
\begin{axis}[x tick label style={/pgf/number format/.cd,%
        scaled x ticks = false,
        set thousands separator={},
        fixed}, yticklabel={$\pgfmathprintnumber{\tick}\%$}, grid=both, minor tick num=9, grid style={line width=.2pt, draw=black!10}, major grid style={line width=.4pt, draw=black!20}, enlargelimits={abs=0.1}, width=12cm, height=8cm, xmin=1970, xmax=2022, ymin=0, ymax=16, xlabel= \textbf{Time}, ylabel= \textbf{Degree of Negative Campaigning}, xtick={1970,1973,1976,1979,1982,1985,1988,1991,1994,1998,2002,2006,2010,2014,2018,2022}, every tick label/.append style={font=\tiny}]
\addplot[color=black, mark=*] 
coordinates{ 
(1970,13.6363658)
(1973,3.4666667)
(1976,9.4786733)
(1979,7.7683621)
(1982,14.6520151)
(1985,11.3144759)
(1988,1.8472911)
(1991,4.14201161)
(1994,5.5229145)
(1998,3.23846942)
(2002,4.75448152)
(2006,3.775099)
(2010,2.680462)
(2014,6.462614250) 
(2018,7.56129860) 
(2022,5.7528533)};
\addlegendentry{Election manifestos}
\end{axis}
\end{tikzpicture}
\end{figure}

答案1

像这样?

在此处输入图片描述

通过使用组图:


\documentclass[12pt]{article}
\usepackage[margin=25mm]{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\usepackage[font=small, labelfont=bf]{caption}
\usepackage{subcaption}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.18}
\usepackage{siunitx}

\begin{document}
\begin{figure}[!htb]
    \centering
\caption{Negative Campaigning in a some western countries Multi-Party System}
    \centering
\begin{tikzpicture}
    \begin{groupplot}[
group style={
    group size=3 by 2,
    y descriptions at=edge left,
    horizontal sep=1em,
    vertical sep=5em,
            },
%
    width=0.285\linewidth, height=5cm,
    scale only axis,
    grid=both, minor tick num=9, 
    grid style={line width=.2pt, draw=black!10},
    major grid style={line width=.4pt, draw=black!20},
    title style = {yshift=-3pt, font=\footnotesize\bfseries},
%
    enlargelimits=false,
    xlabel={Time}, ylabel={Degree of Negative Campaigning},
    label style = {font=\footnotesize},
%
    xtick=data,
    xticklabel style = {font=\tiny, rotate=90,anchor=east,
                        /pgf/number format/.cd,
                        set thousands separator={},
                        fixed},
    ytick={0,2,...,16},
    yticklabel={$\pgfmathprintnumber{\tick}\%$},        
    yticklabel style={font=\tiny},
    ymin=0,     ymax=16,
%
    legend entries = {Election\\ manifestos},
    legend style={legend style={cells={align=left}},
                  font=\scriptsize
                  }
                     ]
\nextgroupplot[title=Switzerland]
\addplot[mark=*]    %color=black, 
    coordinates{(1970,13.6363658)   (1973,3.4666667)    (1976,9.4786733)    (1979,7.7683621)   
                (1982,14.6520151)   (1985,11.3144759)   (1988,1.8472911)    (1991,4.14201161)   
                (1994,5.5229145)    (1998,3.23846942)   (2002,4.75448152)   (2006,3.775099)
                (2010,2.680462)     (2014,6.462614250)  (2018,7.56129860)   (2022,5.7528533)
               };
\nextgroupplot[title=Germany]
\addplot[mark=*]   
    coordinates{(1970,13.6363658)   (1973,3.4666667)    (1976,9.4786733)    (1979,7.7683621)
                (1982,14.6520151)   (1985,11.3144759)   (1988,1.8472911)    (1991,4.14201161)
                (1994,5.5229145)    (1998,3.23846942)   (2002,4.75448152)   (2006,3.775099)
                (2010,2.680462)     (2014,6.462614250)  (2018,7.56129860)   (2022,5.7528533)
               };
\nextgroupplot[title=Austria]
\addplot[mark=*]   
    coordinates{(1970,13.6363658)   (1973,3.4666667)    (1976,9.4786733)    (1979,7.7683621)
                (1982,14.6520151)   (1985,11.3144759)   (1988,1.8472911)    (1991,4.14201161)
                (1994,5.5229145)    (1998,3.23846942)   (2002,4.75448152)   (2006,3.775099)
                (2010,2.680462)     (2014,6.462614250)  (2018,7.56129860)   (2022,5.7528533)
               };

\nextgroupplot[title=Netherland]
\addplot[mark=*]    
    coordinates{(1970,13.6363658)   (1973,3.4666667)    (1976,9.4786733)    (1979,7.7683621)
                (1982,14.6520151)   (1985,11.3144759)   (1988,1.8472911)    (1991,4.14201161)
                (1994,5.5229145)    (1998,3.23846942)   (2002,4.75448152)   (2006,3.775099)
                (2010,2.680462)     (2014,6.462614250)  (2018,7.56129860)   (2022,5.7528533)
               };
\nextgroupplot[title=UK]
\addplot[mark=*]   
    coordinates{(1970,13.6363658)   (1973,3.4666667)    (1976,9.4786733)    (1979,7.7683621)
                (1982,14.6520151)   (1985,11.3144759)   (1988,1.8472911)    (1991,4.14201161)
                (1994,5.5229145)    (1998,3.23846942)   (2002,4.75448152)   (2006,3.775099)
                (2010,2.680462)     (2014,6.462614250)  (2018,7.56129860)   (2022,5.7528533)
               };
\nextgroupplot[title=Sveden]
\addplot[mark=*]   
    coordinates{(1970,13.6363658)   (1973,3.4666667)    (1976,9.4786733)    (1979,7.7683621)
                (1982,14.6520151)   (1985,11.3144759)   (1988,1.8472911)    (1991,4.14201161)
                (1994,5.5229145)    (1998,3.23846942)   (2002,4.75448152)   (2006,3.775099)
                (2010,2.680462)     (2014,6.462614250)  (2018,7.56129860)   (2022,5.7528533)
               };
   
    \end{groupplot}


\end{tikzpicture}
\end{figure}
\end{document}
  • 图表数据重复。
  • 由于图表很窄,我旋转了 x 轴数据。
  • 到目前为止,图例在每个图表中都是重复的。如果它们的内容在所有图表中都相同,您可以考虑将其放在图表组的上方或下方。

相关内容