有没有办法用 tikzpicture 给多个轴添加标题?我不想使用子图,因为每个轴(及其对应的图形)都通过箭头连接到另一个轴。
我有类似的东西:
\begin{figure}
\begin{tikzpicture}
\begin{axis} %axis 1
<code for plot here>
\draw node (bar1) at (some_coordinates){};
\end{axis}
\begin{axis}[ %axis 2
xshift = 3in
]
<code for plot here>
\draw node (bar2) at (some_coordinates) {};
\end{axis}
\begin{axis}[ %axis 3
xshift = 3in,
yshift = -3in,
]
<code for plot here>
\draw node (bar3) at (some_coordinates) {};
\end{axis}
\draw [->,thick,color=red,dashed] (bar1) -- (bar2);
\draw [->,thick,color=red,dashed] (bar2) -- (bar3);
\end{tikzpicture}
\end{figure}
是否可以为每个轴添加标题?
答案1
多轴环境很难连接,但至少你可以groupplot
通过加载groupplots
库来使用。以下是一个例子:
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 2},height=7cm,width=7cm]
\nextgroupplot
\addplot coordinates {(0,0) (1,1) (2,2)};
\draw node (bar1) at (1,0){bar1};
\nextgroupplot
\addplot coordinates {(0,2) (1,1) (2,0)};
\draw node (bar2) at (1,2){bar2};
\nextgroupplot
\addplot coordinates {(0,2) (1,1) (2,1)};
\draw node (bar3) at (1.5,1){bar3};
\nextgroupplot
\addplot coordinates {(0,2) (1,1) (1,0)};
\end{groupplot}
\draw [->,thick,color=red,dashed](bar1)--(bar2);
\draw [->,thick,color=red,dashed](bar2)--(bar3);
\end{tikzpicture}
\end{figure}
\end{document}
答案2
如果您想要实际编号的标题,您可以\captionof
在轴下方的节点中使用。如果您愿意,可以对子图进行编号,例如https://tex.stackexchange.com/a/250032/586
\documentclass{article}
\usepackage{pgfplots}
\usepackage{capt-of}
\begin{document}
\begin{figure}
\begin{tikzpicture}[every axis/.style={width=7cm}]
\begin{axis}[name=axis1] %axis 1
\addplot {rnd};
\node (bar1) at (1,1){};
\end{axis}
\begin{axis}[ %axis 2
xshift = 3in,
name=axis2
]
\addplot {rnd};
\node (bar2) at (1,1) {};
\end{axis}
\begin{axis}[ %axis 3
xshift = 3in,
yshift = -3in,
name=axis3
]
\addplot {rnd};
\node (bar3) at (1,1) {};
\end{axis}
\draw [->,thick,color=red,dashed] (bar1) -- (bar2);
\draw [->,thick,color=red,dashed] (bar2) -- (bar3);
\begin{scope}[every node/.style={text width=7cm,align=left}]
\node [below] at (axis1.south) {\captionof{figure}{First caption}};
\node [below] at (axis2.south) {\captionof{figure}{Second caption}};
\node [below] at (axis3.south) {\captionof{figure}{Third caption}};
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}