我正在尝试调整 tikz 图形中节点的位置,但由于某种原因,我创建的点没有显示在(0,8/3)
所施加的适当坐标中。
@codeR 建议我添加该行\node[dot, label=left:$\lambda_{E-G}$] at (0,8/3) {};
,但是尽管得到了他的帮助,我仍然遇到同样的问题。
代码 :
\documentclass[margin=3mm,tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{angles, arrows.meta,
quotes}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[scale=1,
the_angle/.style args = {#1/#2}{draw,<->,
angle radius=#1,
angle eccentricity=#2,
%anchor=south west,
}, % angle label position
dot/.style = {circle, fill, inner sep=-1.2pt}
]
\pgfplotsset{ticks=none}
\begin{axis}[axis lines=middle,xmin=0,xmax=15,ymin=0,ymax=7, ultra thick,
xlabel=$\scriptstyle \log(t)$,
ylabel=$\scriptstyle \log(R)$,
xlabel style={at={(1,-0.01)},anchor=north},
ylabel style={at={(-0.15,1)},anchor=west},
]
%
\addplot+[no marks,blue,domain=0:8,samples=300, thick] {(1/3)*x} coordinate (A);
\coordinate (O) at (0,0); % intersection with coordinate axis
\coordinate (C) at (2,0);
\addplot+[no marks,dashed,blue,domain=8:14,samples=300, thin] {(1/3)*(x-8)+8/3};
\addplot+[no marks,green,domain=8:14,samples=300, thick] {(1/2)*(x-8)+8/3};
\addplot+[no marks,dashed,green,domain=0:8,samples=300, thin] {(1/2)*(x-8)+8/3};
\draw[gray, thick, dash pattern=on 6pt off 3pt] (0,8/3) -- (8,8/3);
\end{axis}
\pic [the_angle=9mm/1.2, "\qty{30}{\degree}"] {angle = C--O--A};
\node[dot, label=left:$\lambda_{E-G}$] at (0,8/3) {};
\end{tikzpicture}
\end{document}
任何帮助都将不胜感激:谢谢!
真挚地,
PS:有没有办法让轴线精确地连接在同一点?为什么尽管以 (0,0) 为原点,但 x 轴和 y 轴之间会有偏移?谢谢
答案1
问题是轴环境具有不同的“范围”,由坐标系的原点定义(尝试\begin{axis}[..., ymin=-5]
查看此内容)。您观察到的偏移是由于轴箭头处的注释造成的。解决方案是从轴环境内部“保存”点的坐标,然后使用它。我只是给出最后几行
\begin{axis}[...]
...
\draw[gray, thick, dash pattern=on 6pt off 3pt] (0,8/3) -- (8,8/3);
\node (abc) at (0,8/3) {};
\end{axis}
\pic [the_angle=9mm/1.2, "\qty{30}{\degree}"] {angle = C--O--A};
\node[dot, label=left:$\lambda_{E-G}$] at (abc) {};
\end{tikzpicture}
得出以下结果:
我想这就是你想要的?
答案2
要连接两条轴线,请添加line cap=rect
到axis
配置中。
坐标系axis
设置在\begin{axis}
和之间\end{axis}
。您可以按照@BanDoP 的建议,将位置保存为坐标,以便在环境之外使用它axis
。
另一种方法是将\node
命令移到环境内axis
。在这种情况下,必须设置该设置,以避免剪切使用或命令clip mode=individual
绘制的路径。\draw
\node
完整示例(角度标签移出线外):
\documentclass[margin=3mm,tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{angles, arrows.meta, quotes}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}[%
scale=1,
the_angle/.style args = {#1/#2}{draw,<->,
angle radius=#1,
angle eccentricity=#2,
% anchor=south west,
}, % angle label position
dot/.style = {circle, fill, inner sep=-1.2pt}
]
\pgfplotsset{ticks=none}
\begin{axis}[%
axis lines=middle, ultra thick,
line cap=rect,% <-- join axis lines
xmin=0, xmax=15, ymin=0, ymax=7,
xlabel=$\scriptstyle \log(t)$,
ylabel=$\scriptstyle \log(R)$,
xlabel style={at={(1,-0.01)}, anchor=north},
ylabel style={at={(-0.15,1)}, anchor=west},
clip mode=individual,% <-- don't clip tikz commands like \node or \draw
]
%
\addplot+[no marks, blue, domain=0:8, samples=300, thick] {(1/3)*x} coordinate (A);
\coordinate (O) at (0,0); % intersection with coordinate axis
\coordinate (C) at (2,0);
\addplot+[no marks, dashed, blue, domain=8:14, samples=300, thin] {(1/3)*(x-8)+8/3};
\addplot+[no marks, green, domain=8:14, samples=300, thick] {(1/2)*(x-8)+8/3};
\addplot+[no marks, dashed, green, domain=0:8, samples=300, thin] {(1/2)*(x-8)+8/3};
\draw[gray, thick, dash pattern=on 6pt off 3pt] (0,8/3) -- (8,8/3);
\node[dot, label=left:$\lambda_{E-G}$] at (0,8/3) {};
\end{axis}
\pic [the_angle=9mm/1.2, "\qty{30}{\degree}", angle eccentricity=1.4] {angle = C--O--A};
\end{tikzpicture}
\end{document}
答案3
我们可以用
extra y ticks
对于这些功能来说,
samples=2
已经足够要用点标记点,您可以在轮廓中进行标记,然后添加
clip mode=individual
\draw[gray, thick, dash pattern=on 6pt off 3pt] (0,8/3) node[dot,node contents=]-- (8,8/3);
我们可以
siunitx
使用\ang{30}
\qty{30}{\degree}
% \documentclass[margin=3mm,tikz]{standalone} \documentclass[margin=3mm]{standalone}%<-pgfplots load tikz \usepackage{pgfplots} \pgfplotsset{compat=newest} \usetikzlibrary{angles, arrows.meta, quotes} \usepackage{siunitx} \begin{document} \begin{tikzpicture}[scale=1, the_angle/.style args = {#1/#2}{draw,<->, angle radius=#1, angle eccentricity=#2, %anchor=south west, }, % angle label position % dot/.style = {circle, fill, inner sep=-1.2pt} dot/.style = {circle, fill=black, inner sep=0pt,minimum size=2mm}, ] % \pgfplotsset{ticks=none} \begin{axis}[ clip mode=individual,%<-- added if dot marker axis lines=middle, xmin=0,xmax=15, ymin=0,ymax=7, ultra thick, xlabel=$\scriptstyle \log(t)$, ylabel=$\scriptstyle \log(R)$, xlabel style={at={(1,-0.01)},anchor=north}, ylabel style={at={(-0.15,1)},anchor=west}, % % added % extra y ticks={8/3}, extra y tick labels={$\lambda_{E-G}$}, % ytick style={ % /pgfplots/major tick length=2mm,red,very thick}, xtick=\empty, ytick=\empty, ] % \addplot+[no marks,blue,domain=0:8,samples=2, thick] {(1/3)*x} coordinate (A); \coordinate (O) at (0,0); % intersection with coordinate axis \coordinate (C) at (2,0); \addplot+[no marks,dashed,blue,domain=8:14,samples=2, thin] {(1/3)*(x-8)+8/3}; \addplot+[no marks,green,domain=8:14,samples=2, thick] {(1/2)*(x-8)+8/3}; \addplot+[no marks,dashed,green,domain=0:8,samples=2, thin] {(1/2)*(x-8)+8/3}; \draw[gray, thick, dash pattern=on 6pt off 3pt] (0,8/3) node[dot,node contents=]-- (8,8/3); %\node [dot] at (axis cs:0,8/3) {}; \end{axis} \pic [the_angle=9mm/1.3, "\ang{30}"] {angle = C--O--A}; \end{tikzpicture} \end{document}