Graph with cropped letters

Just move the nodes out of the axis environment. (Using clip=false can have undesired side effects such as overshooting plots.)

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,every axis/.append style={
  axis x line=middle,
  axis y line=middle,
  ticks=none}}
\pagestyle{empty}
\begin{document}
\begin{center}
  \begin{tikzpicture}
    \begin{axis}[xmin=-.2,xmax=2.75,ymin=-.2,ymax=2.25]
      \plot[thick,samples=100,domain=.5:2.5] {1/x};
      \coordinate (a1) at (.8,0);
      \coordinate (a2) at (0,1.25);
      \coordinate (b1) at (2,0);
      \coordinate (b2) at (0,.5);
      \draw[thin,dashed](a1)--(a1|-a2)--(a2);
      \draw[thin,dashed](b1)--(b1|-b2)--(b2);
    \end{axis}
    \node[below] at (a1) {\footnotesize$a$};
    \node[below] at (b1) {\footnotesize$b$};
    \node[left] at (a2) {\footnotesize$1/a$};
    \node[left] at (b2) {\footnotesize$1/b$};
  \end{tikzpicture}
\end{center}
\end{document}

enter image description here

There are various other options, e.g. adding these nodes as extra ticks, which also do not get clipped.


I see that you set ticks=none, and then manually added something very much like axis ticks. If you use PGFPLOTS's own tick-placing system, the tick labels do not get clipped.

In this example, there's a lot of keysetting, but less code once the plot is drawn.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,every axis/.append style={
  axis x line=middle,
  axis y line=middle,
  xticklabel style={name=xtick \ticknum},
  yticklabel style={name=ytick \ticknum},
}}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
        xmin=0,xmax=2.5,ymin=0,ymax=2,
        enlargelimits,
        xtick={0.8,2},
        xticklabels={$a$,$b$},
        ytick={0.5,1.25},
        yticklabels={$1/a$,$1/b$},
        tick style={draw=none},
        ticklabel style={font=\footnotesize},
        typeset ticklabels with strut,
    ]
      \addplot[thick,samples=100,domain=.5:2.5]  {1/x};
      \coordinate (O) at (axis cs:0,0);
      \coordinate (a1) at (xtick 0 |- O);
      \coordinate (a2) at (ytick 1 -| O);
      \coordinate (b1) at (xtick 1 |- O);
      \coordinate (b2) at (ytick 0 -| O);
      \draw[thin,dashed](a1)--(a1|-a2)--(a2);
      \draw[thin,dashed](b1)--(b1|-b2)--(b2);
    \end{axis}
  \end{tikzpicture}
\end{document}

sample code output

Notes:

  • We can see that the y tick labels are automatically not clipped.

  • The xticklabel style and yticklabel style keys give names to the nodes which are the tick labels. Then we can locate the a1, a2, b1, and b2 nodes along the axes using those tick labels.

  • Rather than enlarge the limits manually by adding or subtracting a bit to each min and max, the enlargelimits key does that for us.

  • the typeset ticklabels with strut makes the baselines of the a and b tick labels align. We can shift the x tick labels closer to the x axis with xticklabel shift={-1.5mm} or something similar.


Let me convert my comment to an answer. In your case clip=false will work just fine:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,
    axis lines=middle, % <---
    ticks=none}  

\begin{document}
    \begin{tikzpicture}[
every label/.style={font=\footnotesize, text height=1.2ex, inner sep=2pt}
                        ]
\begin{axis}[
    xmin=-.2,xmax=2.75,
    ymin=-.2,ymax=2.25,
    clip=false] % <---
      \plot[thick,samples=100,domain=.5:2.5] {1/x};
    %
      \coordinate[label=below:$a$] (a1) at (0.8,0);   % <---
      \coordinate[label=below:$b$] (b1) at (2.0,0);   % <---
      \coordinate[label=left:$1/a$] (a2) at (0,1.25); % <---     
      \coordinate[label=left:$1/b$] (b2) at (0,0.5);  % <---
    %
    \draw[very thin, densely dashed]   
        (a1) |- (a2)     (b1) |- (b2);  % <---
    \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

Tags:

Ticks

Tikz Pgf