I want to plot data from a table file. The data has quite big gaps in the x-axis, making the actual data barely readable. Is it possible to tell pgfplots to kind of collapse the x-axis in a given range? I added an image of the current plot with the sometimes huge gaps.

data plotted with huge gaps in the x-axis \documentclass[border=5mm]{standalone}

            tick label style={/pgf/number format/fixed}]
            \addplot[black,only marks,mark=+]
               table[x index=0,y index=1]{data.dat};
  • 1
    You can use the axis x discontinuity option. See tex.stackexchange.com/questions/46422/axis-break-in-pgfplots
    – Herr K.
    Dec 9, 2013 at 2:21
  • 1
    You can use an alternative x coordinate and relabel them.
    – percusse
    Dec 9, 2013 at 8:42
  • @Kevin C The discontinuity option would be exactly what I need, except it only does it's thing between 0 and the first data points. What I want to achieve is to tell it in which range it should collapse. In the above example it would be from about 64 to 65, and 66 to 74.
    – aaron
    Dec 9, 2013 at 17:50
  • @percusse I am not that familiar with pgfplots, any more hints on what you mean?
    – aaron
    Dec 9, 2013 at 18:22

1 Answer 1


With the help of http://guido.vonrudorff.de/pgfplots-discontinuities/ I managed to solve my problem. This way includes quite a bit of manual labor, but the result is what I wanted. The idea is to set the min and max range of the plot manually and then shift the ranges to the left so the gaps are closed. Of course, one has to manually set the labels on the x-axis this way.

plot with collapsed, broken x-axis

          xticklabels=  {63.35,63.40,63.45,63.50,63.55,65.35,65.40,65.45,65.50,65.55,74.35,74.40,74.45,74.50,74.55},
          xtick=        {63.35,63.40,63.45,63.50,63.55,63.59,63.64,63.69,63.74,63.79,63.84,63.89,63.94,63.99,64.04},
          x tick label style={rotate=45},
          extra x ticks={63.57,63.80},
          extra x tick style={grid=none, tick label style={xshift=0cm,yshift=.30cm, rotate=-45}},
          extra x tick label={\color{black}{/\!\!/}}
        \addplot[black,only marks,mark=+,restrict x to domain=63.34:63.57] table[x index=0,y expr=\thisrowno{1}] {data.dat};
        %% x expr=\thisrowno{0}-1.76  -> shift to the left so it appears in the plot. Shift labels by the same amount so they fit
        \addplot[black,only marks,mark=+,restrict x to domain=63.58:63.79] table[x expr=\thisrowno{0}-1.76,y expr=\thisrowno{1}] {data.dat};
        \addplot[black,only marks,mark=+,restrict x to domain=63.80:64.05] table[x expr=\thisrowno{0}-10.51,y expr=\thisrowno{1}] {data.dat};
        \draw[black] decorate [decoration={zigzag}] {(axis cs:63.57,-4) -- (axis cs:63.57,0)};
        \draw[black] decorate [decoration={zigzag}] {(axis cs:63.80,-4) -- (axis cs:63.80,0)};

You must log in to answer this question.

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