7

How to remove the tick at x = 9 and y = 7 without removing the grid ?

\documentclass[border=5pt,tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}


\usetikzlibrary[arrows.meta,bending]
\usetikzlibrary{shapes.geometric,positioning}

\begin{document}

\begin{tikzpicture}

\begin{axis}[
 restrict x to domain=0:9, xmax=9, xmin=0,
 restrict y to domain=0:7, ymax=7, ymin=0,
 x=1.5cm,
 y=1.5cm,
 axis x line = bottom,
 axis y line = left,
 axis line style =thick,
 major tick style=black,
 grid=both,
 major grid style=lightgray,
 minor grid style=lightgray,
 minor tick num=1,
 xticklabels={\empty,0,1,2,3,4,5,6,7,8},
 yticklabels={\empty,\empty,1,2,3,4,5,6},
 samples=5000,
 >=stealth,
  ]

 \addplot[smooth,thick] table {

  0     0.5
  0.5   1
  1     2
  1.5   2.875
  2     3.625
  2.25  4
  2.5   4.375
  3     5
  3.5   5.4375
  4     5.75
  4.5   5.9375
  5     6
  5.1   6
  5.25  6
  5.5   6
  6     6
  7     6
  8     6

 };

 \node[above right] at (axis cs:6.9,0.1) {Âge (en année)};
 \node[above right] at (axis cs:0.1,6.5) {Masse (en kg)};

 \draw[dashed,red] (axis cs:1,0)--(axis cs:1,2)--(axis cs:0,2);

 \end{axis}

 \end{tikzpicture}

 \end{document}

enter image description here

0
13

You can use

 xtick={0,...,8},
 ytick={0,...,6},

to suppress the ticks and then

 extra x ticks={9},
 extra y ticks={7},
 extra tick style={tick style={draw=none}},

to add the grid lines back without ticks; of course, now there's no need for xticklabels nor yticklabels. The complete code:

\documentclass[border=5pt,tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}


\usetikzlibrary[arrows.meta,bending]
\usetikzlibrary{shapes.geometric,positioning}
%\pgfplotsset{compat=1.12}

\begin{document}

\begin{tikzpicture}

\begin{axis}[
 restrict x to domain=0:9, xmax=9, xmin=0,
 restrict y to domain=0:7, ymax=7, ymin=0,
 x=1.5cm,
 y=1.5cm,
 axis x line = bottom,
 axis y line = left,
 axis line style =thick,
 major tick style=black,
 grid=both,
 major grid style=lightgray,
 minor grid style=lightgray,
 minor tick num=1,
 xtick={0,...,8},
 ytick={0,...,6},
 extra x ticks={9},
 extra y ticks={7},
 extra tick style={tick style={draw=none}},
 samples=5000,
 >=stealth,
  ]

 \addplot[smooth,thick] table {

  0     0.5
  0.5   1
  1     2
  1.5   2.875
  2     3.625
  2.25  4
  2.5   4.375
  3     5
  3.5   5.4375
  4     5.75
  4.5   5.9375
  5     6
  5.1   6
  5.25  6
  5.5   6
  6     6
  7     6
  8     6

 };

 \node[above right] at (axis cs:6.9,0.1) {Âge (en année)};
 \node[above right] at (axis cs:0.1,6.5) {Masse (en kg)};

 \draw[dashed,red] (axis cs:1,0)--(axis cs:1,2)--(axis cs:0,2);

 \end{axis}

 \end{tikzpicture}

 \end{document}

enter image description here

If you also want to suppress the labels, use

extra x ticks={9}, 
extra x tick label={\null}, 
extra y ticks={7}, 
extra y tick label={\null}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.