0

I want to save space when stacking many axes over each other. The plots have common domain, and I don't want to lose space for the same information repeated (the numbers on the x-axis). Is it possible to disable the x-numbering of ticks ? I found till now the opotion \empty but that removes the ticks so no grids for them can be ploted. I want to keep the grid.

\begin{figure}[!h]
\centering
  \pgfplotsset{width={\textwidth},height={6 cm},
  xmin=0,xmax=7}
\begin{tikzpicture}
\begin{axis}[
    ylabel={$y$},
    grid=major,
%xtick=\empty,
    ]
    \addplot[blue, domain=2:4] {1};
    \addplot[red, dashed, domain=2-2:4-2] {2*x};
\end{axis}
\end{tikzpicture}\vspace{.5 cm}

\begin{tikzpicture}
\begin{axis}[
    ylabel={$y$},
    grid=major,
    ]
    \addplot[blue, domain=2:4] {1};
    \addplot[red, dashed, domain=2-1:4-1] {2*x};
\end{axis}
\end{tikzpicture}\vspace{.5 cm}

\begin{tikzpicture}
\begin{axis}[
    xlabel= {$x$}, ylabel={$y$},
    grid=major,
    ]
    \addplot[blue, domain=2:4] {1};
    \addplot[red, dashed, domain=2:4] {2*x};
\end{axis}
\end{tikzpicture}
\label{fig:sin}
\end{figure}

1 Answer 1

2

You can use xticklabels={}:

enter image description here

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

\begin{document}
\pgfplotsset{width={\textwidth},height={6 cm},
  xmin=0,xmax=7}
\begin{tikzpicture}
\begin{axis}[
    ylabel={$y$},
    grid=major,
    xticklabels={},
    ]
    \addplot[blue, domain=2:4] {1};
    \addplot[red, dashed, domain=2-2:4-2] {2*x};
\end{axis}
\end{tikzpicture}
\end{document}

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.