![虚线轴线](https://linux22.com/image/276761/%E8%99%9A%E7%BA%BF%E8%BD%B4%E7%BA%BF.png)
如何使从原点到每个坐标的轴线变成虚线?例如,我希望从 (0,0,0) 到 (0,0,1) 的轴线为虚线。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{axis}[view={40}{20}, ticks = none, axis on top, axis lines=center, y
dir=reverse, ymin=0, ymax=2, xmin=0, xmax=2, zmin=0, zmax=2,
xlabel=$p_{1}$, ylabel=$p_{2}$, zlabel=$p_{3}$, every axis y label/.append
style={at=(ticklabel* cs:0)}]
\addplot3[thick,mark=*] coordinates {(1,0,0) (0,1,0) (0,0,1)} --cycle;
\node [above right] at (axis cs:1,0,0) {$(1,0,0)$};
\node [above left] at (axis cs:0,1,0) {$(0,1,0)$};
\node [above right] at (axis cs:0,0,1) {$(0,0,1)$};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
也许我的方法过于简单 -dashed white
使用
\draw[dashed,white] (axis cs: 0,0,0)--(axis cs: 0,0,1);
\draw[dashed,white] (axis cs: 0,0,0)--(axis cs: 0,1,0);
\draw[dashed,white] (axis cs: 0,0,0)--(axis cs: 1,0,0);
您需要注释掉axis on top,
它才能使其起作用。
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[scale=1]
\begin{axis}[
view={40}{20},
ticks = none,
%axis on top,
axis lines=center, y
dir=reverse,
ymin=0, ymax=2, xmin=0, xmax=2, zmin=0, zmax=2,
xlabel=$p_{1}$, ylabel=$p_{2}$, zlabel=$p_{3}$,
every axis y label/.append style={at=(ticklabel* cs:0)},
]
\addplot3[thick,mark=*] coordinates {(1,0,0) (0,1,0) (0,0,1)} --cycle;
\node [above right] at (axis cs:1,0,0) {$(1,0,0)$};
\node [above left] at (axis cs:0,1,0) {$(0,1,0)$};
\node [above right] at (axis cs:0,0,1) {$(0,0,1)$};
\draw[dashed,white] (axis cs: 0,0,0)--(axis cs: 0,0,1);
\draw[dashed,white] (axis cs: 0,0,0)--(axis cs: 0,1,0);
\draw[dashed,white] (axis cs: 0,0,0)--(axis cs: 1,0,0);
\end{axis}
\end{tikzpicture}
\end{document}
如果你仔细观察,你会发现它们axis
仍然存在。这可能是好事也可能是坏事……如果你根本不想看到它们,请添加以下thick
命令draw
:
\draw[dashed,white,thick] (axis cs: 0,0,0)--(axis cs: 1,0,0);
答案2
这个老问题有一个解决方案,即绘制白色虚线图案以隐藏部分轴。这会产生伪影,因此这里为任何需要它的人提供了另一种解决方案。
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
view={40}{20},
ticks=none,
axis lines=center,
y dir=reverse,
xmin=0, xmax=2,
ymin=0, ymax=2,
zmin=0, zmax=2,
xlabel=$p_{1}$, ylabel=$p_{2}$, zlabel=$p_{3}$,
every axis y label/.append style={at=(ticklabel* cs:0)},
x axis line style={draw=none, insert path={(axis cs:0,0,0) edge[draw, dashed, -] (axis cs:1,0,0) (axis cs:1,0,0) edge (axis cs:2,0,0)}},
y axis line style={draw=none, insert path={(axis cs:0,0,0) edge[draw, dashed, -] (axis cs:0,1,0) (axis cs:0,1,0) edge (axis cs:0,2,0)}},
z axis line style={draw=none, insert path={(axis cs:0,0,0) edge[draw, dashed, -] (axis cs:0,0,1) (axis cs:0,0,1) edge (axis cs:0,0,2)}},
]
\addplot3[thick,mark=*] coordinates {(1,0,0) (0,1,0) (0,0,1)} -- cycle;
\end{axis}
\end{tikzpicture}
\end{document}