扩展 TikZ/pgfplots 轴箭头而不使用网格

扩展 TikZ/pgfplots 轴箭头而不使用网格

如何在不扩展网格的情况下将轴箭头延伸到网格之外?

这是我能得到的最接近的答案:

\begin{tikzpicture}
  \begin{axis}[
    axis x line  = center,
    axis y line  = center,
    xlabel       = {$\mathrm{V}$},
    ylabel       = {$\mathrm{I}$},
    xlabel style = {anchor = west},
    ylabel style = {above left},
    xmin         = -5,
    xmax         = 6,
    ymin         = -5,
    ymax         = 6,
    xtick        = {-5,-4,...,5},
    ytick        = {-5,-4,...,5},
    grid         = both,
    grid style   = {dashed, gray},
    legend pos   = outer north east
  ]
    \addplot [domain=-5:5,samples=2,mark=*,red] {x/1.667};
    \addplot [domain=-5:5,samples=2,mark=*,blue] {0};
    \legend{
      $R=\SI{1.667}{\ohm}$,
      {open circuit}
    }
  \end{axis}
\end{tikzpicture}

在此处输入图片描述

如您所见,网格也放大了10pt。如何让网格在 x=5 和 y=5 处停止?

答案1

实现所需图表布局的一种方法是:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\usepackage{siunitx}


\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines  = middle,
axis line style = {shorten > =-5mm},
    xlabel       = {$V$},
    ylabel       = {$I$},
    xlabel style = {xshift=5mm, right},
    ylabel style = {yshift=5mm,  left},
%
    xmin         = -5,  xmax         = 5,
    ymin         = -5,  ymax         = 5,
    xtick        = {-5,-4,...,5},
    ytick        = {-5,-4,...,5},
    grid         = both,
    grid style   = {dashed, gray},
    legend pos   = outer north east,
    domain=-5:5,
            ]
    \addplot +[samples=2] {x/1.667};
    \addplot +[samples=2] {0};
    \legend{
      $R=\SI{1.667}{\ohm}$,
      {open circuit}
    }
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容