2

I would like two axes (no graph), both with an axis break at the beginning. The horizontal axis needs to go till 195 and the vertical axis till 80. At the moment, I see the correct values but only the first six of them. My code:

\documentclass{article}
\usepackage{amsmath} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            grid=both,
            minor tick num = 5,
            major grid style={line width=.2pt,draw=gray!60},
            minor grid style={line width=.1pt,draw=gray!20}, % Shorten minor grid lines (optional)
            xlabel={Height (cm)},
            ylabel={Weight (kg)},
            % Define ticks with duplicate labels (for visual representation)
            xticklabels={155, 160, 165, 170, ..., 195},
            yticklabels={45, 50, 55, 60, ..., 80, 85},
            axis x line*=bottom,
            axis y line*=left,
            axis line style={-stealth},
            % Discontinuity visualization (optional)
            after end axis/.append code={
            \draw[thick,decorate,decoration={zigzag,segment length=8,amplitude=2}] (rel axis cs:0.01,0) -- (rel axis cs:0.09,0);
            \draw[thick,decorate,decoration={zigzag,segment length=8,amplitude=2}] (rel axis cs:0,0.01) -- (rel axis cs:0,0.09);
        },
       ]
       \end{axis}
    \end{tikzpicture}

\end{document}

The image that I get is this: grid with incomplete axes

New contributor
ziadmbaroudi is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • Welcome. // Please add the missing lines so your code will compile. Thank you
    – MS-SPO
    Commented Jul 11 at 4:50
  • 1
    Done. Thanks for the tip, @MS-SPO Commented Jul 11 at 9:56

2 Answers 2

3

Seems to me the first and last ticks in both x and y axis are taken as the minimal resp maximal values of x / y when plotting the axes.

So add the following lines to your code:

xmin=153, xmax=197,
ymin=42, ymax=87,

These values then define the start and end positions of the axes (see manual page 329)

As for the discontinuity of the axes pgfplots has a command for that as well (see manual page 280):

axis x discontinuity=crunch,
axis y discontinuity=crunch,

Hope these remarks will help you to solve your question.

3
  • Thank you @alchemist for the suggestions. Unfortunately, adding the xmin, xmax, ymin and ymax has resulted in the x-axis labels ending at 180 and the y-axis labels ending at 70. I will definitely look up discontinuity. Thanks for that tip. Commented Jul 11 at 9:56
  • Actually, @alchemist, with xmin ... ymax that you suggested, I changed xticklabels to xtick, yticklables to ytick and now I see all the labels I wanted. Thank you very much. Would you mind replying with a link to the manual you'd meant? Version 3.1.10 of the TikZ & PGF manual doesn't seem to have anything about discontinuity. Commented Jul 11 at 10:09
  • @ziadmbaroudi : I was refering to the manual of pgfplots as that package was included in your code sample. That manual can be found on mirror.lyrahosting.com/CTAN/graphics/pgf/contrib/pgfplots/doc/…
    – alchemist
    Commented Jul 11 at 10:47
1

Thanks to @alchemist, here is the code that ended up displaying the labels that I needed on both axes:

 \documentclass{article}
 \usepackage{pgfplots}
 \pgfplotsset{compat=newest}
 \usepackage{tikz}
 \begin{document}
 \begin{tikzpicture}
    \begin{axis}[
        grid=both,
        minor tick num = 4,
        major grid style={line width=.2pt,draw=gray!60},
        minor grid style={line width=.1pt,draw=gray!20},
        xlabel={Height (cm)},
        ylabel={Weight (kg)},
        % Define ticks with duplicate labels (for visual representation)
        xmin=147, xmax=196,
        xtick={155, 160, 165, 170, ..., 195},
        ymin=37, ymax=87,
        ytick={45, 50, 55, 60, ..., 85},
        axis x discontinuity = crunch,
        axis y discontinuity = crunch,
        axis x line*=bottom,
        axis y line*=left,
        axis line style={-stealth},
   ]
   \end{axis}
\end{tikzpicture}
\end{document}

Output: enter image description here

New contributor
ziadmbaroudi is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

You must log in to answer this question.

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