我在两个子图中有两个不同的 pgfplots。我想在红色圆圈数据点和蓝色数据点之间画一条线。我使用 LibreOffice Draw 手动添加了线条来向您展示我的意思。
我的代码如下:
\begin{figure}[!htbp]
\centering
\subfigure[Ausgangszustand]{
\resizebox{0.45\textwidth}{!}{
\begin{tikzpicture}
\begin{axis}[
xlabel={Zeit [d]},
ylabel={Auslastung [\%]},
axis lines=left,
xmin=0,
xmax=7.5,
xtick={1,...,8},
ymin=0,
ymax=105,
thick,
grid=both
]
\addplot[smooth,thick] plot coordinates {
(0,35)
(1,60)
(2,20)
(3,95)
(4,45)
(5,30)
(6,60)
(7,55)
};
\addplot+[only marks,mark=o,mark options={scale=3},text mark as node=true] coordinates {
(3,95)
};
\addplot+[only marks,mark=o,mark options={scale=3},text mark as node=true,color=blue] coordinates {
(2,20)
};
\end{axis}
\end{tikzpicture}
}}
\qquad
\subfigure[Zielzustand]{
\resizebox{0.45\textwidth}{!}{
\begin{tikzpicture}
\begin{axis}[
xlabel={Zeit [d]},
ylabel={Auslastung [\%]},
axis lines=left,
xmin=0,
xmax=7.5,
xtick={1,...,8},
ymin=0,
ymax=105,
thick,
grid=both
]
\addplot[smooth,thick] plot coordinates {
(0,45)
(1,55)
(2,40)
(3,70)
(4,55)
(5,35)
(6,50)
(7,45)
};
\addplot+[only marks,mark=o,mark options={scale=3},text mark as node=true] coordinates {
(3,70)
};
\addplot+[only marks,mark=o,mark options={scale=3},text mark as node=true,color=blue] coordinates {
(2,40)
};
\end{axis}
\end{tikzpicture}
}}
\caption{Glättung von Lastspitzen}
\label{fig:Lastspitze}
\end{figure}
我想在图表中绘制以精确数据点为起点和终点的线条。我在谷歌上搜索了一下,但没有找到答案。
答案1
您可以使用 TikZ 覆盖功能,但是您必须避免使用它,\resizebox
因为它会干扰设置为.aux
文件的标记。
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{pgfplots,subfigure}
\begin{document}
\begin{figure}[!htbp]
\centering
\subfigure[Ausgangszustand]{
\begin{tikzpicture}[remember picture]
\begin{axis}[
xlabel={Zeit [d]},
ylabel={Auslastung [\%]},
axis lines=left,
xmin=0,
xmax=7.5,
xtick={1,...,8},
ymin=0,
ymax=105,
thick,
grid=both,
width=0.45\textwidth
]
\addplot[smooth,thick] plot coordinates {
(0,35)
(1,60)
(2,20)
(3,95)
(4,45)
(5,30)
(6,60)
(7,55)
};
\node[red,draw,circle,inner sep=4pt] (red-1) at (axis cs:3,95) {};
\node[blue,draw,circle,inner sep=4pt] (blue-1) at (axis cs:2,20) {};
\end{axis}
\end{tikzpicture}
}%
\qquad
\subfigure[Zielzustand]{
\begin{tikzpicture}[remember picture]
\begin{axis}[
xlabel={Zeit [d]},
ylabel={Auslastung [\%]},
axis lines=left,
xmin=0,
xmax=7.5,
xtick={1,...,8},
ymin=0,
ymax=105,
thick,
grid=both,
width=0.45\textwidth
]
\addplot[smooth,thick] plot coordinates {
(0,45)
(1,55)
(2,40)
(3,70)
(4,55)
(5,35)
(6,50)
(7,45)
};
\node[red,draw,circle,inner sep=4pt] (red-2) at (axis cs:3,70) {};
\node[blue,draw,circle,inner sep=4pt] (blue-2) at (axis cs:2,40) {};
\end{axis}
\end{tikzpicture}
}%
\begin{tikzpicture}[remember picture,overlay]
\draw[dashed,red] (red-1) -- (red-2);
\draw[dashed,blue] (blue-1) -- (blue-2);
\end{tikzpicture}
\caption{Gl\"attung von Lastspitzen}
\label{fig:Lastspitze}
\end{figure}
\end{document}