1

I have the following function in pgfplots:

\begin{tikzpicture}% coordinates
\begin{axis}[xlabel=$x$,ylabel=$y$, axis lines = center, every axis plot/.append style={ultra thick}, ymin=-1,ymax=7]
\addplot [domain=-3:3, samples=100, color=blue,]{x^2};
\addlegendentry{$y=x^2$}
\end{axis}
\end{tikzpicture}

This prints out the following:enter image description here

I'd like to remove the tick labels (but keep the ticks) on everything except the min/max on the axes. So I'd like it to look like this: enter image description here

To that end, it'd be nice to be able to label any tick I wanted to while keeping the ticks visible on the non-labelled ones. This seems simple but I can't seem to figure it out. Thanks in advance!

1 Answer 1

2

If you already know the values, then you can do it easily. One way is to disable all the ticklabels and then label only required ticks.

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
\begin{axis}[axis equal,
xlabel=$x$,ylabel=$y$, axis lines = center, every axis plot/.append style={ultra thick},
xticklabels={},yticklabels={}, % remove ticklabels
xtick distance=1, ytick distance=2, % set the tick distance
extra x ticks={-3,3},extra y ticks={6}, % add required labels
ymin=-1,ymax=7,
]
\addplot [domain=-3:3, samples=100, color=blue,]{x^2};
\addlegendentry{$y=x^2$}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

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.