tikzpgfplots

Remove first and last axis tick in pgfplots


I want to plot a coordinate system like this and I want to get rid of the first and the last tick of the x-axis and the y-axis. Like in my example I also don't want tick labels at the begin and the end of every axis. enter image description here

How can I get rid of the first and the last tick of every axis?

This is my code:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots}
\usepackage{helvet}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest, width=7cm, height=7cm,
every x tick label/.append style={font=\scriptsize\sffamily, yshift=0.2ex},
every y tick label/.append style={font=\scriptsize\sffamily, xshift=0.2ex}}
\begin{document}
\begin{tikzpicture}[font=\small\sffamily]
\begin{axis}[ clip=true, 
xmin=-3, xmax=6,
ymin=-4, ymax=5,
xtick={-3,...,6},
xticklabels={,-2,-1,,1,2,3,4,5,},
ytick={-4,...,5},
yticklabels={,-3,-2,-1,,1,2,3,4,},
minor tick num=1,
axis lines=middle,
xlabel=\textbf{x},
ylabel=\textbf{y},
xmajorgrids=true,
xminorgrids=true,
ymajorgrids=true,
yminorgrids=true,
axis line style={line width=1pt},
every x tick/.style={color=black, thick},
every y tick/.style={color=black, thick}
]
\draw[line width=.5pt](current axis.south west)rectangle(current axis.north east);
\end{axis}
\end{tikzpicture}
\end{document}

Solution

  • Quick and dirty hack:

    \documentclass{standalone}
    \usepackage[utf8]{inputenc}
    \usepackage{tikz,pgfplots}
    \usepackage{helvet}
    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{compat=newest, width=7cm, height=7cm,
    every x tick label/.append style={font=\scriptsize\sffamily, yshift=0.2ex},
    every y tick label/.append style={font=\scriptsize\sffamily, xshift=0.2ex}}
    \begin{document}
    \begin{tikzpicture}[font=\small\sffamily]
    \begin{axis}[ clip=true, 
    xmin=-2.99, xmax=5.99,
    ymin=-3.99, ymax=4.99,
    xtick={-3,...,6},
    xticklabels={,-2,-1,,1,2,3,4,5,},
    ytick={-4,...,5},
    yticklabels={,-3,-2,-1,,1,2,3,4,},
    minor tick num=1,
    axis lines=middle,
    xlabel=\textbf{x},
    ylabel=\textbf{y},
    xmajorgrids=true,
    xminorgrids=true,
    ymajorgrids=true,
    yminorgrids=true,
    axis line style={line width=1pt},
    every x tick/.style={color=black, thick},
    every y tick/.style={color=black, thick}
    ]
    \draw[line width=.5pt](current axis.south west)rectangle(current axis.north east);
    \end{axis}
    \end{tikzpicture}
    \end{document}
    

    enter image description here