3

pgfplot provides the possibility to insert a discontinuity on the axes (see MWE 1 & first srceenshot). However, it seems as this discontinuity is only applicable from the value 0 to ymin/xmin.

I plotted a histogram in which the occurrence of the values between -50 and -1.8 as well as between 3 and 50 are not really relevant to the reader (red boxes). However, I must provide these results. The most important part lies between the values -1.8 and 3 (green boxes). Therefore I thought in this case it would be useful just to plot the relevant part and to depict the irrelevant part with an interrupted interval (e.g. xleft1=-40, xright1=-5 and xleft1=5, xright1=40)

Question:

How can I insert a discontinuity as in MWE 1 between a value xleft and xrigth in my histogram?

MWE1

histograms

MWE 1 (example from pgfplot manual)

\begin{tikzpicture}
\begin{axis}[
    axis x line=bottom,
    axis y line=center,
    tick align=outside,
    axis x discontinuity=crunch,
    xmin=-2, enlargelimits=false
    ]

    \addplot[blue,mark=none,
         domain=-4:4,samples=20] 
        {x*x+x+104};

\end{axis}
\end{tikzpicture}

MWE 2

    \documentclass{article}
    \usepackage{filecontents}
    \usepackage{tikz}
    \usepackage{pgfplots,pgfplotstable}


    \begin{filecontents}{HistoData1.dat}
    x   y
    %-50    5
    -1.8    29.
    -1.6    20.
    -1.4    41.
    -1.2    43.
    -1. 44.
    -0.8    52.
    -0.6    92.
    -0.4    79.
    -0.2    80.
    0.  74.
    0.2 81.
    0.4 52.
    0.6 68.
    0.8 52.
    1.  43.
    1.2 37.
    1.4 34.
    1.6 17.
    1.8 7.
    2.  10.
    2.2 6.
    2.4 5.
    2.6 1.
    2.8 2.
    3.  2.
    %50 10
    \end{filecontents}

    \begin{filecontents}{HistoData2.dat}
    x   y
    -50 5
    -1.8    29.
    -1.6    20.
    -1.4    41.
    -1.2    43.
    -1. 44.
    -0.8    52.
    -0.6    92.
    -0.4    79.
    -0.2    80.
    0.  74.
    0.2 81.
    0.4 52.
    0.6 68.
    0.8 52.
    1.  43.
    1.2 37.
    1.4 34.
    1.6 17.
    1.8 7.
    2.  10.
    2.2 6.
    2.4 5.
    2.6 1.
    2.8 2.
    3.  2.
    50  10
    \end{filecontents}

    \begin{document}

\begin{tikzpicture} 
    \begin{axis}[title={\large 1st plot}
    ]

        \addplot[title={second plot},
            ybar interval,
            fill=blue
        ] table [  
                x=x,
                y=y
        ] {HistoData2.dat} ;

        \draw[green,dashed,thick] (axis cs:-5,0) rectangle (axis cs:5,95);
        \draw[red,dashed,thick] (axis cs:-2,0) rectangle (axis cs:-52,10);
        \draw[red,dashed,thick] (axis cs:1.5,0) rectangle (axis cs:52,7.5);

        \node
        [pin=90:\scriptsize xleft1,fill=black,circle,scale=0.3] 
        (xright1) at (axis cs:-40,5) {};
        \node
        [pin=145:\scriptsize  xright1,fill=black,circle,scale=0.3] 
        (xright1) at (axis cs:-5,5) {};

        \node
        [pin=45:\scriptsize xleft2,fill=black,circle,scale=0.3] 
        (aninnernode) at (axis cs:5,2) {};
        \node
        [pin=90:\scriptsize  xright2,fill=black,circle,scale=0.3] 
        (aninnernode) at (axis cs:40,2) {};

    \end{axis} 
\end{tikzpicture}

\vspace{1.5cm}

\begin{tikzpicture} 
    \begin{axis}[title={\large 2nd plot (relevant part of 1st plot)}
    ]

        \addplot[title={first plot},
            ybar interval,
            fill=blue
        ] table [  
                x=x,
                y=y
        ] {HistoData1.dat} ;

        \draw[green,dashed,thick] (axis cs:-2,0) rectangle (axis cs:3.3,95);

    \end{axis} 
\end{tikzpicture}


\end{document}
3
  • PGFPlots only has builtin solution for discontinuity marks at the upper or lower range of an axis, not in-between. Nov 9, 2012 at 15:37
  • That said, there may be custom solutions around on this site. This question here might be a duplicate of those questions. Nov 9, 2012 at 15:39
  • 1
    @ChristianFeuersänger Probably that one: Axis break in pgfplots Nov 18, 2012 at 1:00

0

Browse other questions tagged .