1

I need to do an empty plot for my students to fill. Surprisingly the options xtick=\empty and ytick=\empty do not work when the plot is empty:

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
 
 \begin{tikzpicture}
 \begin{axis}[width=10cm, height=4cm, scale only axis,
  axis lines=center,
  xtick=\empty, ytick=\empty,
  xlabel=$x$, ylabel=$f$]
%   \addplot {x+1};
 \end{axis}
\end{tikzpicture}
 
\end{document}

example

I have been able to achieve my ends with the option ticks=none as explained here, but this is not totally satisfactory since this workaround does not allow to cancel ticks on a single axis if needed. Besides I was not able to find this option in the Pgfplots documentation.

Why the \empty command does not work here?

1 Answer 1

1

It happens because the range of coordinates calculates according to its content. When it's missing I believe, pgfplots just draws default axis, ignoring most options (notice that axis lines=center doesn't work either).

You have three options:

  1. Disable ticks with ticks=none as you described. If you want to eliminate only x ticks or y ticks, you can set xmajorticks=false or xmajorticks=false similarly

    enter image description here

    \documentclass{article}
    
    \usepackage{pgfplots}
    \pgfplotsset{compat=newest}
    
    \begin{document}
    
     \begin{tikzpicture}
     \begin{axis}[width=10cm, height=4cm, scale only axis,
      axis lines=center,
      xlabel=$x$, ylabel=$f$,
      xmajorticks=false
      ]
     \end{axis}
    
     \end{tikzpicture}
    
    \end{document}
    
  2. Put something invisible via \addplot so the data of axis isn't blank

    enter image description here

    \documentclass{article}
    
    \usepackage{pgfplots}
    \pgfplotsset{compat=newest}
    
    \begin{document}
    
     \begin{tikzpicture}
     \begin{axis}[width=10cm, height=4cm, scale only axis,
      axis lines=center,
      xtick=\empty, ytick=\empty,
      xlabel=$x$, ylabel=$f$,
      ]
       \addplot[draw=none]{0};
     \end{axis}
    
     \end{tikzpicture}
    
    \end{document}
    
  3. And the most correct was is to specify all xmin, xmax, ymin, ymax so the axis doesn't rely on content anymore, but the values you set, thus \empty works. enter image description here

    \documentclass{article}
    
    \usepackage{pgfplots}
    \pgfplotsset{compat=newest}
    
    \begin{document}
    
     \begin{tikzpicture}
     \begin{axis}[width=10cm, height=4cm, scale only axis,
      axis lines=center,
      xtick=\empty, ytick=\empty,
      xlabel=$x$, ylabel=$f$,
      xmin=-1, xmax=5,
      ymin=-3, ymax=2
      ]
     \end{axis}
    
     \end{tikzpicture}
    
    \end{document}
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .