将对象移到前面

将对象移到前面

我想将白点置于轴的前面。如何在不删除“轴在顶部”代码的情况下实现此目的?

当前的: 在此处输入图片描述

我要这个: 在此处输入图片描述

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[grid=both,ymin=-5,ymax=5,xmax=5,xmin=-5,xticklabel=\empty,yticklabel=\empty,axis on top,
               minor tick num=1,axis lines = middle,xlabel=$x$,ylabel=$y$,label style =
               {at={(ticklabel cs:1.1)}}]
   \draw[fill=white,thick] (0,3.4) circle (1.6pt);
  \end{axis}
\end{tikzpicture}
\end{document}

答案1

选项axis on top使轴绘制在“主绘图”(非官方名称)的顶部。似乎可以通过设置分层图形,set layers=axis on top然后将绘图放在最前景的图层上,即设置axis foreground时。axis on top

pgfplots请参阅的软件包手册、文档set layers和中的更多信息/pgfplots/layers/axis on top

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[grid=both,ymin=-5,ymax=5,xmax=5,xmin=-5,xticklabel=\empty,yticklabel=\empty,
               minor tick num=1,axis lines = middle,xlabel=$x$,ylabel=$y$,label style =
               {at={(ticklabel cs:1.1)}},
               set layers=axis on top]
    \addplot expression {x};   % to check axis IS on top of plotting
    \addplot expression {3.5}; % and `\draw` is on top of of axis
    \begin{pgfonlayer}{axis foreground}
      \draw[fill=white,thick] (0,3.4) circle (1.6pt);
    \end{pgfonlayer}
  \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以保存以下axis位置:

\coordinate (foo) at (axis cs:0,3.4);

然后,axis您可以在该位置上绘制任何您想要的东西。例如:

\draw[fill=white,thick] (foo) circle (1.6pt);

在此处输入图片描述

平均能量损失

\documentclass[border=2mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[grid=both,ymin=-5,ymax=5,xmax=5,xmin=-5,xticklabel=\empty,yticklabel=\empty,axis on top,
               minor tick num=1,axis lines = middle,xlabel=$x$,ylabel=$y$,label style =
               {at={(ticklabel cs:1.1)}}]
   \coordinate (foo) at (axis cs:0,3.4);
  \end{axis}
   \draw[fill=white,thick] (foo) circle (1.6pt);
\end{tikzpicture}
\end{document}

相关内容