有沒有辦法用 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}