禁用轴末端的刻度

禁用轴末端的刻度

介绍

感谢薛定谔的猫pgfplot 中的“更智能”轴箭头 我现在在图表末尾添加了一些奇特的箭头。问题是,由于我的箭头现在与图表末尾完美对齐,因此那里的任何刻度标记现在都有些多余。

问题

我想要做的是不绘制恰好位于轴的最末端的轴刻度,因为它们现在有点多余。

例子

例子

平均能量损失

\documentclass{article}

\usepackage{pgfplots}
\usetikzlibrary{arrows.meta,calc}
\pgfplotsset{
    no marks,
    minor x tick num=1,
    enlarge x limits=false,
    every x tick/.style={thick},
    every y tick/.style={thick},
    tick align=outside,
    axis lines=middle,
    inner axis line style={-},clip mode=individual,execute at end axis={
    \path[tips=proper] let \p1=($(rel axis cs:1,1)-(axis cs:0,0)$),
     \p2=($(axis cs:0,0)-(rel axis cs:0,0)$)
     in %\pgfextra{\typeout{\x1,\x2,\y1,\y2}}
     \ifdim\x1>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}]
      ($({rel axis cs:1,0} |- {axis cs:0,0})+($(1.5mm,0)-(0,0)$)$)
     \fi
     \ifdim\x2>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}]
      ($({rel axis cs:0,0} |- {axis cs:0,0})+($(-1.5mm,0)-(0,0)$)$)
     \fi
     \ifdim\y1>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}]
      ($({rel axis cs:0,1} -| {axis cs:0,0})+($(0,1.5mm)-(0,0)$)$)
     \fi
     \ifdim\y2>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}]
      ($({rel axis cs:0,0} -| {axis cs:0,0})+($(0,-1.5mm)-(0,0)$)$)
     \fi;
    }
}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[domain=0:1]
        \addplot+[]{x};
    \end{axis}
\end{tikzpicture}

\end{document}

注意:

这看起来可能没什么,但对于满的我正在使用的选项集: 在此处输入图片描述

答案1

您可以作弊并将和设置xtick placement toleranceytick placement tolerance负值。

\documentclass{article}

\usepackage{pgfplots}
\usetikzlibrary{arrows.meta,calc}
\pgfplotsset{xtick placement tolerance=-1mm,ytick placement tolerance=-1mm,
    no marks,
    minor x tick num=1,
    enlarge x limits=false,
    every x tick/.style={thick},
    every y tick/.style={thick},
    tick align=outside,
    axis lines=middle,
    inner axis line style={-},clip mode=individual,execute at end axis={
    \path[tips=proper] let \p1=($(rel axis cs:1,1)-(axis cs:0,0)$),
     \p2=($(axis cs:0,0)-(rel axis cs:0,0)$)
     in %\pgfextra{\typeout{\x1,\x2,\y1,\y2}}
     \ifdim\x1>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}]
      ($({rel axis cs:1,0} |- {axis cs:0,0})+($(1.5mm,0)-(0,0)$)$)
     \fi
     \ifdim\x2>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}]
      ($({rel axis cs:0,0} |- {axis cs:0,0})+($(-1.5mm,0)-(0,0)$)$)
     \fi
     \ifdim\y1>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}]
      ($({rel axis cs:0,1} -| {axis cs:0,0})+($(0,1.5mm)-(0,0)$)$)
     \fi
     \ifdim\y2>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}]
      ($({rel axis cs:0,0} -| {axis cs:0,0})+($(0,-1.5mm)-(0,0)$)$)
     \fi;
    }
}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[domain=0:1]
        \addplot+[]{x};
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

此技巧可让您避免上一个问题中讨论的超调问题。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{arrows.meta,calc}

\pgfplotsset{xtick placement tolerance=-2mm,ytick placement tolerance=-2mm,
    no marks,
    minor x tick num=1,
    enlarge x limits=false,
    every x tick/.style={thick},
    every y tick/.style={thick},
    tick align=outside,
    axis lines=middle,
    inner axis line style={-},clip mode=individual,execute at end axis={
    \path[tips=proper] let \p1=($(rel axis cs:1,1)-(axis cs:0,0)$),
     \p2=($(axis cs:0,0)-(rel axis cs:0,0)$)
     in %\pgfextra{\typeout{\x1,\x2,\y1,\y2}}
     \ifdim\x1>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}] ({rel axis cs:1,0} |- {axis cs:0,0})
     \fi
     \ifdim\x2>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}] ({rel axis cs:0,0} |- {axis cs:0,0})
     \fi
     \ifdim\y1>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}] ({rel axis cs:0,1} -| {axis cs:0,0})
     \fi
     \ifdim\y2>0pt
      (axis cs:0,0) edge[-{Latex[length=1.5mm]}] ({rel axis cs:0,0} -| {axis cs:0,0})
     \fi;
    }}

\begin{document}
\begin{tabular}{cc}
\begin{tikzpicture}
    \begin{axis}[domain=0:1]
        \addplot+{x};
    \end{axis}
\end{tikzpicture} &
\begin{tikzpicture}
    \begin{axis}[domain=0:1]
        \addplot+{-x};
    \end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}
    \begin{axis}[domain=-1:0]
        \addplot+{x};
    \end{axis}
\end{tikzpicture} &
\begin{tikzpicture}
    \begin{axis}[domain=-1:0]
        \addplot+{-x};
    \end{axis}
\end{tikzpicture}\\
\begin{tikzpicture}
    \begin{axis}[domain=-1:1]
        \addplot+{-x};
    \end{axis}
\end{tikzpicture}
\end{tabular}
\end{document}

在此处输入图片描述

相关内容