[Tex/LaTex] How to add an extra tick without adding a new line to the grid

pgfplotstikz-pgf

I need to add an extra tick to the x-axis without adding a new grid line at the new x value, the problem is that I'm using extra ticks to get a complete grid (it is one solution that was given to me in this post) wich lines start and end at integer boundaries of the x and y-axis.

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=center,
    grid=major,
    grid style={dotted, cyan},
    anchor=origin,
    xlabel = $x$, ylabel =$y$,  % Set the labels
    xmin= -4, xmax= 4,
    ymin=-4, ymax=4,
    xtick={-3,-2,...,3},
    ytick={-3,-2,...,3},
    extra x ticks={-4,3.14, 4},
    extra y ticks={-4, 4},
    extra tick style={grid=major, grid style={dotted, cyan}},
    extra x tick labels={,\hspace{.4em}$\pi$,},
    extra y tick labels={},
    color=cyan
]
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Best Answer

To add extra tick in the x axis, you can use

extra x tick style={grid=none},

in the options:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=center,
    grid=major,
    grid style={dotted, cyan},
    anchor=origin,
    xlabel = $x$, ylabel =$y$,  % Set the labels
    xmin= -4, xmax= 4,
    ymin=-4, ymax=4,
    xtick={-3,-2,...,3},
    ytick={-3,-2,...,3},
    extra x ticks={-4,3.14, 4},
    extra y ticks={-4, 4},
    extra tick style={grid=major, grid style={dotted, cyan}},
    extra x tick labels={,\hspace{.4em}$\pi$,},
    extra y tick labels={},
    extra x tick style={grid=none}, %% <<-----
    color=cyan
]
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

This will make the last grid lines on either side of x axis to disapper which can be drawn using

\draw[dotted,cyan] (4,-4) -- (4,4)
                   (-4,-4) -- (-4,4);
\end{axis}

enter image description here

Here is the manually drawing option mentioned by Gonzalo:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines=center,
    grid=major,
    grid style={dotted, cyan},
    anchor=origin,
    xlabel = $x$, ylabel =$y$,  % Set the labels
    xmin= -4, xmax= 4,
    ymin=-4, ymax=4,
    xtick={-3,-2,...,3},
    ytick={-3,-2,...,3},
    extra x ticks={-4, 4},
    extra y ticks={-4, 4},
    extra tick style={grid=major, grid style={dotted, cyan}},
    extra x tick labels={},%,\hspace{.4em}$\pi$,},
    extra y tick labels={},
    %extra x tick style={grid=none}, %% <<-----
    color=cyan
]
 \draw[very thin,gray] (3.14,0.1) -- (3.14,-0.1)node[anchor=north west,inner xsep=0pt,text=cyan] {$\pi$};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here