דילוג לתוכן

כמה גרפים ברשת עם groupplots

טוענים את הספרייה groupplots, פותחים סביבת groupplot עם group style={group size=2 by 1}, ומתחילים כל גרף עם \nextgroupplot.

שני גרפים זה לצד זה

הספרייה groupplots מסדרת כמה צירים ברשת, באותו גודל ועם מסגרות מיושרות. group size=2 by 1 פירושו שתי עמודות ושורה אחת. כל \nextgroupplot מתחיל את התא הבא, בסדר הקריאה.

שני גרפים בשורה אחת

\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}

אפשרויות על groupplot חלות על כל התאים; אפשרויות על \nextgroupplot רק על התא הזה.

רשת של 2 על 2 עם תוויות משותפות

ברשת, תוויות השנתות והצירים הפנימיות חוזרות על עצמן. xlabels at=edge bottom ו-ylabels at=edge left משאירים את תוויות הצירים רק בגרפים החיצוניים, ו-xticklabels at=edge bottom עושה אותו דבר לתוויות השנתות של x.

ארבעה גרפים עם תוויות בקצוות החיצוניים

\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}

גרף ראשי וחלונית שאריות

לתאים יכולים להיות גבהים וטווחים שונים. פריסה נפוצה היא גרף נתונים ומתחתיו חלונית קטנה של שאריות (residuals), עם ציר x משותף.

נתונים ושאריות

\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}

מפתחות של group style

מפתחמה הוא עושהב-Scissor LaTeX
group size=C by Rעמודות על שורותעובד
horizontal sep, vertical sepהמרווח בין מסגרות הציריםעובד
xlabels at=edge bottom, ylabels at=edge leftתוויות צירים רק בגרפים החיצוניים (או all)עובד
xticklabels at=edge bottom, yticklabels at=edge leftתוויות שנתות רק בגרפים החיצוניים (או all)עובד
group name=gשם להתייחסות לתאים, כמו g c1r1מתקבל; התייחסויות לתאים לא נתמכות

מה שונה מהתקנת TeX

הספרייה היא חלק מ-pgfplots; ראו את הפרק "groupplots" במדריך ב-CTAN: ctan.org/pkg/pgfplots. אם pgfplots חדש לך, כדאי להתחיל בגרפים עם pgfplots.

ראו גם גרפי קווים, צירים לוגריתמיים ו-pgfplots.

שאלות ותשובות

איך יוצרים תת-גרפים ב-LaTeX?

משתמשים בספרייה groupplots של pgfplots: \usepgfplotslibrary{groupplots}, ואז \begin{groupplot}[group style={group size=2 by 2}] ו-\nextgroupplot אחד לכל גרף.

איך משתפים את תוויות הצירים בקבוצת גרפים?

מוסיפים xlabels at=edge bottom ו-ylabels at=edge left ל-group style, וקובעים xlabel ו-ylabel על ה-groupplot.

שני גרפים יכולים לחלוק מקרא אחד?

לכל תא יש מקרא משלו. שמים את המקרא בתא אחד וממקמים אותו עם legend style={at={(x,y)}, anchor=...}.

כל דוגמה בדף הזה מסודרת על ידי Scissor LaTeX בזמן בניית האתר. עודכן לאחרונה: 2026-11-07.