我想创建一个 2x2 + 1 的图,像......
---------------------------| | 图 1 | 图 2 | | ------------------- 地块 5 | | 图 3 | 图 4 | | ---------------------------|
我该如何实现呢?使用 pgfplots 包?
答案1
以下是一些入门知识
我已经使用了subcaption
包,除其他内容外,还提供subfigure
环境。您可以将其视为minipage
- 它采用所有相同的强制和可选参数。
根据需要调整宽度:)
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{pgfplots}
\usepackage{subcaption}
\pgfplotsset{
every axis/.append style={
scale only axis,
width=\textwidth,
}
}
\begin{document}
\begin{figure}%
\begin{minipage}{.5\textwidth}
\centering
\begin{subfigure}{.4\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{}
\end{subfigure}%
\hfill
\begin{subfigure}{.4\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{}
\end{subfigure}%
\\
\begin{subfigure}{.4\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{}
\end{subfigure}%
\hfill
\begin{subfigure}{.4\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{}
\end{subfigure}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\begin{subfigure}{.9\textwidth}
\begin{tikzpicture}
\begin{axis}
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{}
\end{subfigure}
\end{minipage}%
\caption{}%
\label{}%
\end{figure}
\end{document}
答案2
如果不需要单独的标题,只需在axis
后面添加一个groupplot
并适当偏移即可。
下面,我在手册的groupplot
示例中添加了一个额外的轴。
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{
every axis/.append style={
scale only axis,
xmin=0, xmax=2,
ymin=0, ymax=2,
xtick distance=1,
ytick distance=1,
enlarge x limits=true,
enlarge y limits=true,
}
}
\def\sep{0.5cm}
\def\side{1.5cm}
\begin{groupplot}[
group style={
group name=small, % so that plots' coords can be ref'd
group size=2 by 2,
x descriptions at=edge bottom,
y descriptions at=edge left,
horizontal sep=\sep,
vertical sep=\sep,
},
height=\side,
width=\side,
]
\nextgroupplot
\addplot coordinates {(0,0) (1,1) (2,2)};
\nextgroupplot
\addplot coordinates {(0,2) (1,1) (2,0)};
\nextgroupplot[
ylabel=$y$ label,
y label style={at=(ticklabel cs:1.15)},
]
\addplot coordinates {(0,2) (1,1) (2,1)};
\nextgroupplot[
xlabel=$x$ label,
x label style={at=(ticklabel cs:0.85)},
]
\addplot coordinates {(0,2) (1,1) (1,0)};
\end{groupplot}
\begin{axis}[
name=big,
at={($(small c2r2.south east)+(\sep+2ex,0)$)}, % offset
height=\side*2+\sep,
width=\side*2+\sep,
]
\addplot coordinates {(0,1.5) (1,0.5) (2,1.5)};
\end{axis}
\end{tikzpicture}
\end{document}