0

I'm trying to create a diagram where some distance/data is skipped, and this is indicated on the axis by a small symbol, either a little zigzag or some diagonal lines, as shown in the below example images.

What's the best way to reproduce this symbol/styling in tikz? (On a side note, is any particular symbol considered standard, or is preferred over others?)

example1 example2

I am currently producing the axis of my diagram using the below code, and would like the symbol to appear at about the (-2,6) point.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\begin{tikzpicture}
    \draw[black,ultra thick] [-stealth] (-2,0) -- (-2,14);
    \node[rotate=90,font=\Large,anchor=south] at (-2,7) {Energy};
\end{tikzpicture}
\end{figure}
\end{document}
2

On way that gives you a lot of freedom is to suppress (in part) the drawing of the axis, and to redraw it after the plot with decorations:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
 separate axis lines,
 x axis line style= { draw opacity=0 }]
\addplot[] {x^2};

%store coodinates
\path[-] (rel axis cs:0,0)     coordinate(botstart)
          --(rel axis cs:0.7,0)coordinate(interruptbotA)
         (rel axis cs:0.87,0)  coordinate(interruptbotB)
         --(rel axis cs:1,0)   coordinate(botstop);

\path[-] (rel axis cs:0,1)     coordinate(topstart)
         --(rel axis cs:0.7,1) coordinate(interrupttopA)
         (rel axis cs:0.87,1)  coordinate(interrupttopB)
         --(rel axis cs:1,1)   coordinate(topstop);
\end{axis}

%Draw the axis with a decoration:
\draw(botstart)-- (interruptbotA) decorate[decoration=zigzag]{--(interruptbotB)} -- (botstop);
\draw(topstart)-- (interrupttopA) decorate[decoration=zigzag]{--(interrupttopB)} -- (topstop);

\end{tikzpicture}

\end{document} 

enter image description here

One can also draw inside the axis environment but then you probably will have to disable clipping.

0

I've managed to find a simplistic but effective solution, which I thought I'd share. Essentially I just replace the single line from my original code with three consecutive lines, with the middle one having a zigzag decoration. This produces the zigzag symbol that indicates a discontinuity of the line/graph. I don't know how to produce the other type of symbol, but since this solution gets the job done, I don't really care.

The important thing to note for anyone trying to adapt this for their own purposes, is that the segment length of the middle line needs to be equal to its length, which is determined from its start and end coordinates. This ensures the zigzag is only one wavelength.

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}

    \begin{figure}
        \begin{tikzpicture}
        \draw[black,ultra thick] (-2,0) -- (-2,5.5);
        \draw[black,ultra thick,decorate,decoration={zigzag,segment length=3mm, amplitude=5pt}] (-2,5.5) -- (-2,5.8);
        \draw[black,ultra thick] [-stealth] (-2,5.8) -- (-2,14);
        \node[rotate=90,font=\Large,anchor=south] at (-2,7) {Energy};
        \end{tikzpicture}
    \end{figure}

\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.