The following example solves the function drawing by dividing it into parts:
- Line at y=-1 from left to the y axis at x=0.
- Line at y=1 from the y axis at x=0 to the right.
- Red dot at point (0, 0).
- White dot with black circle to exclude points at (0, -1) and (-1, 0).
The minus sign of y tick "-1" would be overprinted by the red line. Therefore,
the tick is set as extra tick with a style that moves the tick mark to the right.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{amsmath}
\DeclareMathOperator{\sgn}{sgn}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,
ylabel={$\sgn(x)$},
xmin=-3, xmax=3,
ymin=-1.5, ymax=1.5,
xtick=\empty,
ytick={0, 1},
extra y ticks={-1},
extra y tick style={
tick label style={anchor=west, xshift=3pt},
},
function line/.style={
red,
thick,
samples=2,
},
single dot/.style={
red,
mark=*,
},
empty point/.style={
only marks,
mark=*,
mark options={fill=white, draw=black},
},
]
\addplot[function line, domain=\pgfkeysvalueof{/pgfplots/xmin}:0] {-1};
\addplot[function line, domain=0:\pgfkeysvalueof{/pgfplots/xmax}] {1};
\addplot[single dot] coordinates {(0, 0)};
\addplot[empty point] coordinates {(0, -1) (0, 1)};
\end{axis}
\end{tikzpicture}
\end{document}

sign, see feature request 81. – Heiko Oberdiek Sep 13 '15 at 10:17\addplot {}? – sergej Sep 13 '15 at 10:40fpu, which is used bypgfplots. The link to the feature request only meant, that a definition is not needed at all with recent pgf/TikZ version,signcan be used directly. – Heiko Oberdiek Sep 13 '15 at 10:56\addplot+[no marks,samples=201] {sign(x)};– percusse Sep 13 '15 at 16:40