67

I have a TikZ/PGF axis enviroment where by default numbers are shown along the ticks.

I want it to look like this:

Axis without tick numbers

(Axis without tick numbers)

I found out how to modify the ticks itself using something like

    x tick label style={major tick length=0pt}

in the options of an axis environment. But I couldn't find out how to modify the numbers along the ticks itself. Isn't there an option to hide them?

My current code to generate the 1st example:

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      title={Test Axis},
      xlabel={Test X Label},
      ylabel={Test Y Label},
    ]
    \end{axis}
  \end{tikzpicture}
\end{document}
2
  • Just thought, that it would maybe work defining 'empty' coords like this: "x coords={}" But unfortunately it didn't help. Any other ideas?
    – eliasp
    Nov 28 '10 at 20:10
  • Turns out, 'x coords' is completely invalid. What I actually meant is "xtick={}".
    – eliasp
    Nov 28 '10 at 20:17
74

Just add yticklabels={,,} to the options for the axis environment. Your example then looks like shown below.

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[%
      title={Test Axis},
      xlabel={Test X Label},
      ylabel={Test Y Label},
      yticklabels={,,}
    ]
    \end{axis}
  \end{tikzpicture}
\end{document}

This feature is documented in Section 4.14.2 (Tick Alignment: Positions and Shifts) on page 180 of the pgfplots 1.4.1 manual. Quite hidden in the last example of the mentioned section.

4
  • 2
    Thanks a lot. That's the easiest solution so far, although it still requires to move the axis label manually, as it isn't repositioned although the labels are gone now. For me it also worked using "yticklabels={}", is there a specific reason for using "yticklabels={,,}"?
    – eliasp
    Nov 28 '10 at 21:50
  • I just read in this form in the manual. But good to know that an empty pair of braces also works. The manual positioning of the y-label is annoying but at the moment seems to be without alternative. Perhaps it's on the To-Do-list of the package maintainer. Nov 28 '10 at 21:58
  • 1
    @Thorsten actually, the manual positioning /was/ on the to-do-list. However, to maintain backwards compatibility, it has not been fixed automatically. Adding \pgfplotsset{compat=1.3} (or a more recent choice like 1.4 or 1.5) will automatically move the axis labels. Jul 30 '11 at 18:41
  • Is there any way to silence the warning that this raises? "You have an axis with empty range (in direction y). Replacing it with a default range and clearing all plots." Dec 13 '19 at 21:55
30

The line

\pgfplotsset{ticks=none}

removes both ticks an labels.

Regarding hiding only the tick labels: one idea is to set the tick label color to the backround color. For example:

\pgfplotsset{tick label style={color=white},
  label style={font=\small},
  legend style={font=\small}

To shift the axis label, additionally modify the corresponding style, for example:

\pgfplotsset{every axis x label/.style={
  at={(0.5,0)},
  below,
  yshift=-5pt}}

Adjust the yshift parameter. Similar for the y axis.

\pgfplotsset{every axis y label/.style={
  at={(0,0.5)},
  xshift=-15pt,
  rotate=90}}

alt text

2
  • Ok, this workaround achieves my goal partially - the ticks + tick numbers are gone. The problem with this solution: The position of the axis label doesn't change as if the items would be really hidden.
    – eliasp
    Nov 28 '10 at 20:21
  • 1
    No problem, additionally modify x label/.style, I'll edit the answer.
    – Stefan Kottwitz
    Nov 28 '10 at 20:26
20

I've stumbled upon a nice solution using \empty as argument for the labels you want to hide, e.g. yticklabels=\empty.

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{pgfplots}
\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      title={Test Axis},
      xlabel={Test X Label},
      ylabel={Test Y Label},
      yticklabels=\empty,
    ]
    \end{axis}
  \end{tikzpicture}
\end{document}

The above produces this picture

1
3

In my opinion, the cleanest way to remove all tick labels for the y axis is to use yticklabel=\empty or yticklabel={\empty} (xticklabel=\empty would do the same for the x axis). Note that there is no s in yticklabel!

This works because the /pgfplots/xticklabel, /pgfplots/yticklabel and /pgfplots/zticklabel keys accept a {〈code〉} argument that defines how to format each tick in a generic way—see the excerpt from the pgfplots manual reproduced below.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      title={Test axis},
      xlabel={Test $x$ label},
      ylabel={Test $y$ label},
      yticklabel=\empty,
    ]
    \end{axis}
  \end{tikzpicture}
\end{document}

screenshot

Quote from the pgfplots manual

What follows is the beginning of the documentation for the /pgfplots/xticklabel, /pgfplots/yticklabel and /pgfplots/zticklabel keys in the pgfplots manual, version 1.16 (latest release as of January 2020).

/pgfplots/xticklabel={〈command〉}
/pgfplots/yticklabel={〈command〉}
/pgfplots/zticklabel={〈command〉}

These keys change the TeX command which creates the tick labels assigned to each tick position (see options xtick and ytick).

This is one of the two options to assign tick labels directly. The other option is xticklabels={〈label list〉} (or yticklabels={〈label list〉}). The option xticklabel offers higher flexibility while xticklabels is easier to use.

The argument 〈command〉 can be any TeX text. The following commands are valid inside of 〈command〉:

  • \tick The current element of option xtick (or ytick).
  • \ticknum The current tick number, starting with 0 (it is a macro containing a number).
  • \nexttick This command is only valid if the x tick label as interval option is set (or the corresponding variable for y). It will contain the position of the next tick, that means the right boundary of the tick interval.

The default argument is

  • \axisdefaultticklabel for normal plots:

    \def\axisdefaultticklabel{$\pgfmathprintnumber{\tick}$}
    
  • \axisdefaultticklabellog for log plots:
    \def\axisdefaultticklabellog{%
        \pgfkeysgetvalue{/pgfplots/log number format code/.@cmd}\pgfplots@log@label@style
        \expandafter\pgfplots@log@label@style\tick\pgfeov
    }
    
1
  • Excellent answer!!
    – manooooh
    Jul 8 '20 at 0:41

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.