我想要一个带有矩形节点的范围(参见下面屏幕截图中的红色矩形)...
- 位于地块上方
- 以 30 为中心(轴坐标)
- 跨度60(轴坐标)
到目前为止,在我的代码中,我必须手动将范围在轴坐标方面向上移动。这也minimum width=60
使得节点的长度只有大约 25。我必须使用范围,因为我将向其中添加几个其他节点。
\begin{tikzpicture}
\begin{axis}[
clip mode=individual,
]
\begin{scope}[shift={(0,135)}]
\node[rectangle,draw,inner sep=0,minimum width=60,minimum height=0.25cm] (arc1) at (30,0) {};
\end{scope}
\addplot [thick,red]
table {%
0.0 102.0237699221741
0.25 101.72068526496476
15.0 45.16414016873146
30.0 17.64127821777247
45.0 45.16414016873147
59.75 101.7206852649648
60.0 102.02376992217408
};
\addplot [thick]
table {%
0.0 17.64106301486778
0.25 17.697226406877196
15.0 45.163818883512945
30.0 102.02354812212525
45.0 45.163818883512945
59.75 17.697226406877185
60.0 17.64106301486777
};
\end{axis}
\end{tikzpicture}
编辑:稍后我将在范围内包含许多节点。带有矩形的线条在另一个 tikzpicture 中定义。但为了避免嵌套 tikzpictures,我将复制范围内的内容,如下所示:
\begin{tikzpicture}
\begin{axis}[
clip mode=individual,
]
\begin{scope}[shift={(0,135)}]
\draw (-5,0) -- (65,0);
\node[rectangle,fill=white,draw,inner sep=0,minimum width=10,minimum height=0.25cm] (arc1) at (10,0) {};
\node[rectangle,fill=white,draw,inner sep=0,minimum width=10,minimum height=0.25cm] (arc1) at (15,0) {};
\node[rectangle,fill=white,draw,inner sep=0,minimum width=20,minimum height=0.25cm] (arc1) at (30,0) {};
\node[rectangle,fill=white,draw,inner sep=0,minimum width=10,minimum height=0.25cm] (arc1) at (60,0) {};
\end{scope}
\addplot [thick,red]
table {%
0.0 102.0237699221741
0.25 101.72068526496476
15.0 45.16414016873146
30.0 17.64127821777247
45.0 45.16414016873147
59.75 101.7206852649648
60.0 102.02376992217408
};
\addplot [thick]
table {%
0.0 17.64106301486778
0.25 17.697226406877196
15.0 45.163818883512945
30.0 102.02354812212525
45.0 45.163818883512945
59.75 17.697226406877185
60.0 17.64106301486777
};
\end{axis}
\end{tikzpicture}
答案1
宽度的一个选项可能是使用TikZ 库let
中的语法calc
来计算 60 个 x 轴单位的距离。您想要一种不同的移位方法吗?
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
clip mode=individual,
]
\addplot [thick,red]
table {%
0.0 102.0237699221741
0.25 101.72068526496476
15.0 45.16414016873146
30.0 17.64127821777247
45.0 45.16414016873147
59.75 101.7206852649648
60.0 102.02376992217408
};
\addplot [thick]
table {%
0.0 17.64106301486778
0.25 17.697226406877196
15.0 45.163818883512945
30.0 102.02354812212525
45.0 45.163818883512945
59.75 17.697226406877185
60.0 17.64106301486777
};
\begin{scope}[shift={(0,135)}]
\path let \p1=(0,0), \p2=(60,0) in
node[rectangle,draw,inner sep=0,minimum width=\x2-\x1,minimum height=0.25cm] (arc1) at (30,0) {};
\end{scope}
\end{axis}
\end{tikzpicture}
\end{document}