Beberapa plot dalam kisi dengan groupplots
Muat pustaka groupplots, buka lingkungan groupplot dengan group style={group size=2 by 1}, lalu mulai setiap plot dengan \nextgroupplot.
Dua plot berdampingan
Pustaka groupplots menata beberapa sumbu dalam kisi, dengan ukuran yang sama dan bingkai yang sejajar. group size=2 by 1 berarti dua kolom dan satu baris. Setiap \nextgroupplot memulai sel berikutnya, sesuai urutan baca.
Dua plot dalam satu baris
\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}Opsi pada groupplot berlaku untuk setiap sel; opsi pada \nextgroupplot hanya untuk sel itu.
Kisi 2 kali 2 dengan label bersama
Dalam kisi, label tanda skala dan label sumbu bagian dalam akan berulang. xlabels at=edge bottom dan ylabels at=edge left hanya menampilkan label sumbu pada plot terluar, dan xticklabels at=edge bottom melakukan hal yang sama untuk label tanda skala x.
Empat plot dengan label di tepi luar
\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}Plot utama dan panel residu
Sel-sel bisa punya tinggi dan rentang yang berbeda. Tata letak yang umum adalah plot data dengan panel residu kecil di bawahnya, yang berbagi sumbu x.
Data dan residu
\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}Kunci group style
| Kunci | Fungsinya | Di Scissor LaTeX |
|---|---|---|
group size=C by R | kolom kali baris | Berfungsi |
horizontal sep, vertical sep | jarak antarbingkai sumbu | Berfungsi |
xlabels at=edge bottom, ylabels at=edge left | label sumbu hanya pada plot terluar (atau all) | Berfungsi |
xticklabels at=edge bottom, yticklabels at=edge left | label tanda skala hanya pada plot terluar (atau all) | Berfungsi |
group name=g | nama untuk merujuk sel, sebagai g c1r1 | Diterima; rujukan ke sel tidak didukung |
Apa yang berbeda dari instalasi TeX
Pustaka ini adalah bagian dari pgfplots; lihat bagian "groupplots" di manual di CTAN: ctan.org/pkg/pgfplots. Mulailah dengan plot dengan pgfplots jika Anda baru mengenal pgfplots.
Lihat juga Plot garis, Sumbu logaritmik, dan pgfplots.
Tanya jawab
Bagaimana cara membuat subplot di LaTeX?
Pakai pustaka groupplots dari pgfplots: \usepgfplotslibrary{groupplots}, lalu \begin{groupplot}[group style={group size=2 by 2}] dan satu \nextgroupplot per plot.
Bagaimana cara berbagi label sumbu dalam plot berkelompok?
Tambahkan xlabels at=edge bottom dan ylabels at=edge left ke group style, lalu atur xlabel dan ylabel pada groupplot.
Bisakah dua plot berbagi satu legenda?
Setiap sel punya legendanya sendiri. Letakkan legenda di satu sel dan atur posisinya dengan legend style={at={(x,y)}, anchor=...}.
Setiap contoh di halaman ini ditata oleh Scissor LaTeX saat situs dibuat. Terakhir diperbarui 2026-11-07.