【问题标题】:How Do I Create a Groupplot in Overleaf/Latex?如何在 Overleaf/Latex 中创建 Groupplot?
【发布时间】:2022-11-17 00:45:04
【问题描述】:

所以我正在使用 Overleaf 并制作了一个包含九条不同线条的折线图。它看起来像这样:

但是,我希望每一行都有一个单独的图形,但图形应该全部组合在一起,所以最后看起来像这样(但不是 3,3,它应该是 3,3,3):

任何人都知道如何解决这个问题?这是我的代码:

    \documentclass[12pt]{article}
    \usepackage{pgfplots}
    \usepackage{pgfplotstable}
    \usepackage{tikz}
    \begin{document}
    
    \begin{figure}[!htb]
        \centering
    \caption{Trait Attacks 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=30, xlabel= \textbf{Time}, ylabel= \textbf{Degree of Trait Attacks}, 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=purple,,mark=*]
    coordinates{ 
    (1970,9.803922)
    (1973,3.703704)
    (1976,3.738318)
    (1979,3.726708)
    (1982,5.882353)
    (1985,6.4516129)
    (1988,1.5463918)
    (1991,2.419355)
    (1994,3.7593985)
    (1998,1.538462)
    (2002,2.272727)
    (2006,3.703704)
    (2010,0)
    (2014,0) 
    (2018,0) 
    (2022,0)};
    \addplot[color=red,,mark=*]
    coordinates{ 
    (1970,9.489051)
    (1973,3.703704)
    (1976,6.666667)
    (1979,9.183673)
    (1982,25)
    (1985,6.849315)
    (1988,3.703704)
    (1991,4.4247788)
    (1994,3.149606)
    (1998,3.703704)
    (2002,3.703704)
    (2006,3.703704)
    (2010,0)
    (2014,0) 
    (2018,0) 
    (2022,0)};
    \addplot[color=lime,,mark=*]
    coordinates{ 
    (1988,3.703704)
    (1991,0)
    (1994,3.703704)
    (1998,1.234568)
    (2002,3.703704)
    (2006,3.703704)
    (2010,0)
    (2014,0) 
    (2018,0) 
    (2022,0)};
    \addplot[color=green,,mark=*]
    coordinates{ 
    (1970,3.703704)
    (1973,3.703704)
    (1976,1.923077)
    (1979,3.2942104)
    (1982,3.703704)
    (1985,3.703704)
    (1988,3.703704)
    (1991,3.448276)
    (1994,3.703704)
    (1998,3.703704)
    (2002,4.5112782)
    (2006,3.703704)
    (2010,0)
    (2014,0) 
    (2018,0) 
    (2022,0)};
    \addplot[color=blue,,mark=*]
    coordinates{ 
    (1970,3.703704)
    (1973,3.703704)
    (1976,3.703704)
    (1979,3.703704)
    (1982,3.703704)
    (1985,4.8275862)
    (1988,3.703704)
    (1991,3.333333)
    (1994,5)
    (1998,4.242424)
    (2002,2.1097046)
    (2006,4.3010753)
    (2010,0)
    (2014,0)
    (2018,0)  
    (2022,0)};
    \addplot[color=teal,mark=*]
    coordinates{ 
    (1991,3.703704)
    (1994,3.703704)
    (1998,1.020408)
    (2002,2.139037)
    (2006,1.8348624)
    (2010,0)
    (2014,0)
    (2018,0)
    (2022,0)};
    \addplot[color=brown,,mark=*]
    coordinates{ 
    (2010,0)
    (2014,0)
    (2018,0)
    (2022,0)};
    \addplot[color=cyan,,mark=*]
    coordinates{ 
    (1970,9.756098)
    (1973,2.564103)
    (1976,2)
    (1979,5.333333)
    (1982,6.25)
    (1985,6.593407)
    (1988,3.703704)
    (1991,0.621118)
    (1994,1.298701)
    (1998,3.703704)
    (2002,0.7272727)
    (2006,3.703704)
    (2010,0)
    (2014,0) 
    (2018,0) 
    (2022,0)};
    \addplot[color=yellow,,mark=*]
    coordinates{ 
    (1991,2.1390374)
    (1994,0)};
    \legend{V, S, MP, C, L, KD, SD, M, NyD}
    \end{axis}
    \end{tikzpicture}
    \end{figure}
    \end{document}

【问题讨论】:

    标签: latex overleaf


    【解决方案1】:

    尝试使用 subcaption 包中的 subfigures...
    我使用了我的另一个答案中不同的 tikz 图片。

    documentclass[12pt]{article}
        usepackage{pgfplots}
        usepackage{pgfplotstable}
        usepackage{subcaption}
        usepackage{tikz}
        egin{document}
        
        egin{figure}[!htb]
            centering
               egin{subfigure}[b]{0.3	extwidth}
                 centering
                 caption{country A}
                 egin{tikzpicture}
                    %% vertices
                    draw[fill=black] (0,0) circle (1.5pt);
                    draw[fill=black] (3/2,0) circle (1.5pt);
                    draw[fill=black] (0.75,1.2) circle (1.5pt);
                    %% vertex labels
                    
    ode at (-0.2,-0.3) {$v_{3}$};
                    
    ode at (1.7,-0.3) {$v_{2}$};
                    
    ode at (0.75,1.5) {$v_{1}$};
                    %%% edges
                    draw[thick] (0,0) -- (3/2,0) -- (0.75,1.2);
                    end{tikzpicture}
                 label{subfig:countryA}
             end{subfigure}
             hfill
             egin{subfigure}[b]{0.3	extwidth}
                 centering
                 caption{country B}
                egin{tikzpicture}
                    %% vertices
                    draw[fill=black] (0,0) circle (1.5pt);
                    draw[fill=black] (3/2,0) circle (1.5pt);
                    draw[fill=black] (0.75,1.2) circle (1.5pt);
                    %% vertex labels
                    
    ode at (-0.2,-0.3) {$v_{3}$};
                    
    ode at (1.7,-0.3) {$v_{2}$};
                    
    ode at (0.75,1.5) {$v_{1}$};
                    %%% edges
                    draw[thick] (0,0) -- (3/2,0) -- (0.75,1.2);
                    end{tikzpicture}
                 label{subfig:countryB}
             end{subfigure}
             hfill
             egin{subfigure}[b]{0.3	extwidth}
                 centering
                 caption{country C}
                 egin{tikzpicture}
                %% vertices
                draw[fill=black] (0,0) circle (1.5pt);
                draw[fill=black] (3/2,0) circle (1.5pt);
                draw[fill=black] (0.75,1.2) circle (1.5pt);
                %% vertex labels
                
    ode at (-0.2,-0.3) {$v_{3}$};
                
    ode at (1.7,-0.3) {$v_{2}$};
                
    ode at (0.75,1.5) {$v_{1}$};
                %%% edges
                draw[thick] (0,0) -- (3/2,0) -- (0.75,1.2);
                end{tikzpicture}
                 label{subfig:countryC}
             end{subfigure}
             
                  egin{subfigure}[b]{0.3	extwidth}
                 centering
                 caption{country D}
                 egin{tikzpicture}
                    %% vertices
                    draw[fill=black] (0,0) circle (1.5pt);
                    draw[fill=black] (3/2,0) circle (1.5pt);
                    draw[fill=black] (0.75,1.2) circle (1.5pt);
                    %% vertex labels
                    
    ode at (-0.2,-0.3) {$v_{3}$};
                    
    ode at (1.7,-0.3) {$v_{2}$};
                    
    ode at (0.75,1.5) {$v_{1}$};
                    %%% edges
                    draw[thick] (0,0) -- (3/2,0) -- (0.75,1.2);
                    end{tikzpicture}
                 label{fsubfig:countryD}
             end{subfigure}
             hfill
             egin{subfigure}[b]{0.3	extwidth}
                 centering
                 caption{country E}
                egin{tikzpicture}
                    %% vertices
                    draw[fill=black] (0,0) circle (1.5pt);
                    draw[fill=black] (3/2,0) circle (1.5pt);
                    draw[fill=black] (0.75,1.2) circle (1.5pt);
                    %% vertex labels
                    
    ode at (-0.2,-0.3) {$v_{3}$};
                    
    ode at (1.7,-0.3) {$v_{2}$};
                    
    ode at (0.75,1.5) {$v_{1}$};
                    %%% edges
                    draw[thick] (0,0) -- (3/2,0) -- (0.75,1.2);
                    end{tikzpicture}
                 label{subfig:countryE}
             end{subfigure}
             hfill
             egin{subfigure}[b]{0.3	extwidth}
                 centering
                 caption{country F}
                 egin{tikzpicture}
                %% vertices
                draw[fill=black] (0,0) circle (1.5pt);
                draw[fill=black] (3/2,0) circle (1.5pt);
                draw[fill=black] (0.75,1.2) circle (1.5pt);
                %% vertex labels
                
    ode at (-0.2,-0.3) {$v_{3}$};
                
    ode at (1.7,-0.3) {$v_{2}$};
                
    ode at (0.75,1.5) {$v_{1}$};
                %%% edges
                draw[thick] (0,0) -- (3/2,0) -- (0.75,1.2);
                end{tikzpicture}
                 
                 label{subfig:countryF}
             end{subfigure}
             caption{Trait Attacks in the Swedish Multi-Party System 1970-2022.}
            label{fig:six_graphs}
    
        end{figure}
        end{document}
    

    【讨论】:

      猜你喜欢
      • 2022-08-09
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 2019-12-20
      • 2022-11-02
      • 2023-01-03
      • 2023-01-26
      相关资源
      最近更新 更多