1

I have a chart with very higher values in two columns than others, causing a very tall chart. Since I do not have any median values, I would like to 'merge' the intervals to ignore irrelevant information.

This is what I have: enter image description here

I want something like this, instead: enter image description here

How can I achieve it?

MWE:

\usepackage{pgf,tikz}
\usepackage{pgfplots}

    \begin{tikzpicture}
    [scale=0.5]
    \begin{axis}[
    ybar,
    enlarge x limits=0.04,
    enlarge y limits=0,
    legend style={at={(0.5,-0.3)}, anchor=north,legend columns=-1},
    nodes near coords style={anchor=west, rotate=90},   
    ylabel={Time (ns)},
    width=20cm, 
    symbolic x coords=
       {A,
        B,
        C,
        D,
        E,
        F,
        G,
        H,
        I,
        J,
        K,
        L,
        M,
        N,
        O,
        P,
        Q,
        R,
        S,
        T,
    },
    xtick=data,
    nodes near coords, 
    nodes near coords align={vertical},
    x tick label style={rotate=60,anchor=east},
    ]

    \addplot coordinates {
        (A,27.53  )
        (B,33.71  )
        (C,9238.36)
        (D,9184.26)
        (E,119.82 )
        (F,57.62  )
        (G,28.11  )
        (H,101.59 )
        (I,245.64 )
        (J,316.80 )
        (K,107.50 )
        (L,334.93 )
        (M,395.91 )
        (N,558.37 )
        (O,588.47 )
        (P,166.14 )
        (Q,183.95 )
        (R,619.40 )
        (S,95.75  )
        (T,134.50 )};

    \addplot coordinates {
        (A,79.48  )
        (B,95.78  )
        (C,9926.58)
        (D,9864.55)
        (E,314.25 )
        (F,165.87 )
        (G,58.52  )
        (H,188.77 )
        (I,188.34 )
        (J,343.45 )
        (K,196.34 )
        (L,1387.44)
        (M,1671.64)
        (N,604.58 )
        (O, 688.11)
        (P,286.23 )
        (Q,936.79 )
        (R,757.05 )
        (S,205.32 )
        (T,200.74 )};
    \legend{Option1,Option2}
    \end{axis}
    \end{tikzpicture}
  • Welcome to TeX.SX! You can use this solution. A related, but still open question is here – Bobyandbob Jul 20 '17 at 14:34
  • Almost worked. But when I try to crop the values above "2000", I'm missing the original values above "9000", althoug the layout become like I wanted. Any work around? – Kaz Jul 20 '17 at 15:44
  • You have to modify the code wite something like ymax=2000 and restrict y to domain*=0:2015(linked alternative solution). Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. – Bobyandbob Jul 20 '17 at 16:25
  • @Bobyandbob, check this out: is my attempt to make it work like the answer you provide. pastebin.com/MdSMRL4A – Kaz Jul 20 '17 at 18:16
  • I would prefer to use ymax=1700, restrict y to domain*=0:1850, or ymax=2000, restrict y to domain*=0:2150,(as a suggestion). But this solution is only an alternativ and do not answer your question (directly). – Bobyandbob Jul 20 '17 at 18:46
3

Since you did not supply an MWE, I started with this one. There are still issues to work out, like how to put numbers on each column without duplicates.

Basically the idea is to literally merge two plots with different ranges (but the same scale). In this case I only removed the interval from 12-18, but the principle should hold for any size gap.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\begin{tikzpicture}
\begin{axis}[name=top,
    scale only axis, height=4cm, ymin=18, ymax=30,% define y scale
    every axis plot post/.style={/pgf/number format/fixed},
    ybar=5pt,
    bar width=12pt,
    x=3cm,
    axis x line=none,
    xtick=data,
    enlarge x limits=0.2,
    symbolic x coords={A,B,C},
    axis lines*=left,
    axis y discontinuity=parallel,
    ytickmin=20
    ]
\addplot coordinates {(A,2) (B,0.5) (C,10)};
\addplot coordinates {(A,20) (B,30) (C,1)};
\addplot coordinates {(A,6) (B,11) (C,7)};
\end{axis}

\draw[white,thick] (top.south east) -- (top.south west);% erase bottom edge
\pgfmathsetlengthmacro{\height}{4cm/(30-18)*12}% retain common scale

\begin{axis}[yshift={-\height},
    scale only axis, height={\height}, ymin=0, ymax=12,
    every axis plot post/.style={/pgf/number format/fixed},
    ybar=5pt,
    bar width=12pt,
    x=3cm,
    xtick=data,
    enlarge x limits=0.2,
    symbolic x coords={A,B,C},
    %restrict y to domain*=0:12, % Cut values off at 12
    axis lines*=left
    ]
\addplot coordinates {(A,2) (B,0.5) (C,10)};
\addplot coordinates {(A,20) (B,30) (C,1)};
\addplot coordinates {(A,6) (B,11) (C,7)};
\end{axis}
\end{tikzpicture}
\end{document}

demo

  • I think I'm going with your solution. This is my resulT: i.imgur.com/6tRsg4p.jpg. Only thing that bothers me is the "0.9" on y axis after "1800" and 10^4, make bad to read and breake the format. There's a way to avoid this kind of notation? – Kaz Jul 20 '17 at 22:13
  • Figured out using (\pgfplotsset{scaled y ticks=false}). Result: i.imgur.com/chyb7hN.png. Thank you all! – Kaz Jul 20 '17 at 22:21
  • I would have use ytickmin=9200. Otherwise, looks good. – John Kormylo Jul 21 '17 at 1:51

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.