Lumaktaw sa nilalaman

Ilang plot sa isang grid gamit ang groupplots

I-load ang groupplots library, magbukas ng groupplot environment na may group style={group size=2 by 1}, at simulan ang bawat plot gamit ang \nextgroupplot.

Dalawang plot na magkatabi

Inaayos ng groupplots library ang ilang axis sa isang grid, na may parehong laki at nakahanay na frames. Ang group size=2 by 1 ay nangangahulugang dalawang column at isang row. Sinisimulan ng bawat \nextgroupplot ang susunod na cell, ayon sa pagkakasunod ng pagbasa.

Dalawang plot sa isang row

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[
      group style={group size=2 by 1, horizontal sep=1.5cm},
      width=6cm, height=4.5cm, xlabel=$t$,
    ]
    \nextgroupplot[title={Position}, ylabel=$x$]
    \addplot[blue, thick, domain=0:4, samples=40] {x^2/2};
    \nextgroupplot[title={Velocity}, ylabel=$v$]
    \addplot[red, thick, domain=0:4] {x};
  \end{groupplot}
\end{tikzpicture}
\end{document}

Nalalapat sa bawat cell ang options sa groupplot; sa cell na iyon lang ang options sa \nextgroupplot.

2 by 2 na grid na may shared labels

Sa isang grid, umuulit ang mga panloob na tick label at axis label. Pinapanatili ng xlabels at=edge bottom at ylabels at=edge left ang axis labels sa mga panlabas na plot lang, at ganoon din ang ginagawa ng xticklabels at=edge bottom para sa x tick labels.

Apat na plot na may labels sa panlabas na gilid

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[
      group style={
        group size=2 by 2,
        horizontal sep=1.2cm, vertical sep=1cm,
        xlabels at=edge bottom, ylabels at=edge left,
        xticklabels at=edge bottom,
      },
      width=5.5cm, height=4cm,
      xlabel=$t$, ylabel=$y$, domain=0:6, samples=50,
    ]
    \nextgroupplot \addplot[blue] {sin(deg(x))};
    \nextgroupplot \addplot[red] {cos(deg(x))};
    \nextgroupplot \addplot[teal] {exp(-x/2)};
    \nextgroupplot \addplot[orange] {x/6};
  \end{groupplot}
\end{tikzpicture}
\end{document}

Pangunahing plot at residual panel

Puwedeng magkakaiba ang taas at range ng mga cell. Karaniwang layout ang data plot na may maliit na panel ng residuals sa ilalim nito, na magkapareho ang x axis.

Data at residuals

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
  \begin{groupplot}[
      group style={group size=1 by 2, vertical sep=0.4cm, xticklabels at=edge bottom},
      width=8cm, xmin=0, xmax=5,
    ]
    \nextgroupplot[height=5cm, ylabel={Signal}]
    \addplot+[only marks] coordinates {(1,2.1) (2,3.9) (3,6.2) (4,7.8)};
    \addplot[red, domain=0:5] {2*x};
    \nextgroupplot[height=3cm, xlabel=$x$, ylabel={Residual}, ymin=-0.5, ymax=0.5]
    \addplot+[only marks] coordinates {(1,0.1) (2,-0.1) (3,0.2) (4,-0.2)};
    \addplot[gray, dashed, domain=0:5] {0};
  \end{groupplot}
\end{tikzpicture}
\end{document}

Mga key ng group style

KeyAno ang ginagawa nitoSa Scissor LaTeX
group size=C by Rcolumns by rowsGumagana
horizontal sep, vertical sepespasyo sa pagitan ng axis framesGumagana
xlabels at=edge bottom, ylabels at=edge leftaxis labels sa panlabas na plots lang (o all)Gumagana
xticklabels at=edge bottom, yticklabels at=edge lefttick labels sa panlabas na plots lang (o all)Gumagana
group name=gpangalan para tukuyin ang mga cell, bilang g c1r1Tinatanggap; hindi suportado ang pagtukoy sa mga cell

Ang naiiba sa isang TeX installation

Bahagi ng pgfplots ang library; tingnan ang section na "groupplots" ng manual sa CTAN: ctan.org/pkg/pgfplots. Magsimula sa plots gamit ang pgfplots kung bago ka sa pgfplots.

Tingnan din ang Line plots, Logarithmic axes at pgfplots.

Mga tanong at sagot

Paano ako gagawa ng subplots sa LaTeX?

Gamitin ang groupplots library ng pgfplots: \usepgfplotslibrary{groupplots}, tapos \begin{groupplot}[group style={group size=2 by 2}] at isang \nextgroupplot bawat plot.

Paano ko gagawing shared ang axis labels sa isang group plot?

Idagdag ang xlabels at=edge bottom at ylabels at=edge left sa group style, at itakda ang xlabel at ylabel sa groupplot.

Puwede bang iisang legend ang gamitin ng dalawang plot?

May sariling legend ang bawat cell. Ilagay ang legend sa isang cell at iposisyon ito gamit ang legend style={at={(x,y)}, anchor=...}.

Bawat halimbawa sa page na ito ay tina-typeset ng Scissor LaTeX kapag binubuo ang site. Huling na-update noong 2026-11-07.