Question
I add the origin to my graph with
after end axis/.code={\path (axis cs:0,0) node [anchor=north west,yshift=-0.075cm] {0} node [anchor=south east,xshift=-0.075cm] {0};}
(code found here).
This works fine is the origin is on my axis.
But, there are problems if 0 is not in the values taken by y (see the pictures below).
Is there a way to fix this issue?
By this, I mean an option that would display the origin only when needed.
Pictures
first picture

second picture
I cannot put it here, but it prints two pages!!!

Code
first code
\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[grid = major,
clip = true,
clip mode=individual,
axis x line = middle,
axis y line = middle,
xlabel={$x$},
xlabel style={at=(current axis.right of origin), anchor=west},
ylabel={$y$},
ylabel style={at=(current axis.above origin), anchor=south},
domain = 2:5,
xmin = 2,
xmax = 5,
enlarge y limits={rel=0.13},
enlarge x limits={rel=0.07},
restrict y to domain=1:2,
ymin = 1,
ymax = 2,
after end axis/.code={\path (axis cs:0,0) node [anchor=north west,yshift=-0.075cm] {0} node [anchor=south east,xshift=-0.075cm] {0};}]
\addplot[color=Gold3, samples=1000, smooth, ultra thick, unbounded coords=jump, no markers] gnuplot{atan(x)-1/2};
\end{axis}
\end{tikzpicture}
\end{document}
second code
\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[grid = major,
clip = true,
clip mode=individual,
axis x line = middle,
axis y line = middle,
xlabel={$x$},
xlabel style={at=(current axis.right of origin), anchor=west},
ylabel={$y$},
ylabel style={at=(current axis.above origin), anchor=south},
domain = 2:5,
xmin = 2,
xmax = 5,
enlarge y limits={rel=0.13},
enlarge x limits={rel=0.07},
%restrict y to domain=1:2,
%ymin = 1,
%ymax = 2,
after end axis/.code={\path (axis cs:0,0) node [anchor=north west,yshift=-0.075cm] {0} node [anchor=south east,xshift=-0.075cm] {0};}]
\addplot[color=Gold3, samples=1000, smooth, ultra thick, unbounded coords=jump, no markers] gnuplot{atan(x)-1/2};
\end{axis}
\end{tikzpicture}
\end{document}

rel axis csinstead ofaxis csto set the origin. – Henri Menke Apr 08 '14 at 17:26axis descriptioncoordinate system instead:after end axis/.code={ \node[left=2pt] at (axis description cs:0,0) {0}; \node[below=2pt] at (axis description cs:0,0) {0}; }– Gonzalo Medina Apr 08 '14 at 17:290is out the range, the origin in this case should not be displayed. – Colas Apr 08 '14 at 17:33beforethan withafter. More precisely,before end axis/.code={\path (axis cs:0,0) node [anchor=north west,yshift=-0.075cm] {0} node [anchor=south east,xshift=-0.075cm] {0} ;}is better. – Colas Apr 08 '14 at 18:06before end axisyou are still within theaxisenvironment so thatpgfcan determine if that text is within the bounds of the plot, butafter end axispgfis unable to make that determination. – Peter Grill Apr 08 '14 at 18:12middlewhy would you want zero as the tick label? – percusse Apr 08 '14 at 19:07clip mode=individualdoes not apply the clip path to paths like your node... – Christian Feuersänger Apr 08 '14 at 20:59