2

How can I put 0 at origin?

\documentclass[tikz,border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
axis lines=middle,
xmin=-5,xmax=5,
ymin=-5,ymax=5,
restrict y to domain=-4:4,
xtick={-5,-4,-3,-2,-1.41421,-1,0,1,1.41421,2,3,4,5},ytick= 
{-4,-3,-2,-1,0,1,2,3,4},
xticklabels={-5,-4,-3,-2,$-\sqrt{2}$,-1,0,1,$\sqrt{2}$,2,3,4,5},yticklabels= 
{-4,-3,-2,-1,0,1,2,3,4},
ticklabel style={font=\tiny,fill=white},
axis line style={latex-latex},
axis line style={->},
x label style={at={(ticklabel* cs:1)},
anchor=west,},
y label style={at={(ticklabel* cs:1)},
anchor=south},
xlabel={$x$},
ylabel={$y$}
]
\addplot [
domain=-5:5,
samples=300,
color=black,
]
{(x^2-2)/(1-x^2)};

\addplot[dashed, latex-latex, samples=200, domain=-5:5] {-1} 
node[above,pos=0.1,font=\footnotesize]{};
\addplot [dashed, latex-latex, samples=200, domain=-4:4] (-1,x) node 
[pos=0.1, anchor=north, font=\footnotesize, sloped] {};
\addplot [dashed, latex-latex, samples=200, domain=-4:4] (1,x) node 
[pos=0.1, anchor=north, font=\footnotesize, sloped] {};
\end{axis}
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688

2 Answers2

3

You can add a 0 manually by using:

\path (axis cs:0,0) 
     node [font=\tiny,anchor=north west,yshift=-0.075cm] {0} 
     node [font=\tiny,anchor=south east,xshift=-0.075cm] {0};

See here for more details and an alternative method.

\documentclass[tikz,border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
axis lines=middle,
xmin=-5,xmax=5,
ymin=-5,ymax=5,
restrict y to domain=-4:4,
xtick={-5,-4,-3,-2,-1.41421,-1,0,1,1.41421,2,3,4,5},ytick= 
{-4,-3,-2,-1,0,1,2,3,4},
xticklabels={-5,-4,-3,-2,$-\sqrt{2}$,-1,0,1,$\sqrt{2}$,2,3,4,5},yticklabels= 
{-4,-3,-2,-1,0,1,2,3,4},
ticklabel style={font=\tiny,fill=white},
axis line style={latex-latex},
axis line style={->},
x label style={at={(ticklabel* cs:1)},
anchor=west,},
y label style={at={(ticklabel* cs:1)},
anchor=south},
xlabel={$x$},
ylabel={$y$}
]
\addplot [
domain=-5:5,
samples=300,
color=black,
]
{(x^2-2)/(1-x^2)};

\addplot[dashed, latex-latex, samples=200, domain=-5:5] {-1} 
node[above,pos=0.1,font=\footnotesize]{};
\addplot [dashed, latex-latex, samples=200, domain=-4:4] (-1,x) node 
[pos=0.1, anchor=north, font=\footnotesize, sloped] {}; 
\addplot [dashed, latex-latex, samples=200, domain=-4:4] (1,x) node 
[pos=0.1, anchor=north, font=\footnotesize, sloped] {}; 
after end axis/.code={
        \path (axis cs:0,0) 
            node [font=\tiny,anchor=north west,yshift=-0.075cm] {0} 
            node [font=\tiny,anchor=south east,xshift=-0.075cm] {0};
    }   
\end{axis}
\end{tikzpicture}
\end{document}
ofenrohr
  • 133
3

Manually, putting \node [anchor=north] at (axis cs:.15,-.07) {$\scriptscriptstyle 0$}; I think that it's a good compromise. Surely and with the utmost humility I absolutely do not compete with the absolute best with tikz-pgf on this site. The red line certifies that there is an almost perfect alignment.

enter image description here

\documentclass[tikz,border=5pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{datavisualization}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
axis lines=middle,
xmin=-5,xmax=5,
ymin=-5,ymax=5,
restrict y to domain=-4:4,
xtick={-5,-4,-3,-2,-1.41421,-1,0,1,1.41421,2,3,4,5},ytick= 
{-4,-3,-2,-1,0,1,2,3,4},
xticklabels={-5,-4,-3,-2,$-\sqrt{2}$,-1,0,1,$\sqrt{2}$,2,3,4,5},yticklabels= 
{-4,-3,-2,-1,0,1,2,3,4},
ticklabel style={font=\tiny,fill=white},
axis line style={latex-latex},
axis line style={->},
x label style={at={(ticklabel* cs:1)},
anchor=west,},
y label style={at={(ticklabel* cs:1)},
anchor=south},
xlabel={$x$},
ylabel={$y$}
]
\addplot [
domain=-5:5,
samples=300,
color=black,
]
{(x^2-2)/(1-x^2)};
\addplot[dashed, latex-latex, samples=200, domain=-5:5] {-1} 
node[above,pos=0.1,font=\footnotesize]{};
\addplot [dashed, latex-latex, samples=200, domain=-4:4] (-1,x) node 
[pos=0.1, anchor=north, font=\footnotesize, sloped] {};
\addplot [dashed, latex-latex, samples=200, domain=-4:4] (1,x) node 
[pos=0.1, anchor=north, font=\footnotesize, sloped] {};
\node [anchor=north] at (axis cs:.15,-.07) {$\scriptscriptstyle 0$};
\end{axis}
\end{tikzpicture}
\end{document}
Sebastiano
  • 54,118