0

I have been trying to plot some column bars but some results are overwhelming and make the other disappear from the plot. Is it possible to separate those values in another plot next to the other one?

My code is :

\begin{figure}[h]
\centering
\pgfplotsset{compat=1.16}
\begin{tikzpicture}
    \begin{axis}[legend pos=outer north east,
        width=12cm, 
        ybar,
        bar width=7pt,
        xlabel=pH,
        symbolic x coords={A,B,C,D,E},
        xtick={A,B,C,D,E},
        xticklabels={10,7.5,5.2,3.8,3.0},
        ylabel=Size (d.nm),
        enlarge x limits={0.2},
        ymin=0,
        ymode=log,
        ymajorgrids=true,
        scaled ticks=false,
        xtick style={
            /pgfplots/major tick length=0pt,
        }
    ]
        \addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit ,
        ] coordinates {
            (A,15.23)+-(A,0.0346410161513768)
            (B,16.8466666666667)+-(B,0.14224392195568)
            (C,18.1166666666667)+-(C,0.187705443004015)
            (D,18.6866666666667)+-(D,0.14571661996263)
            (E,18.4033333333333)+-(E,0.117189305541646)
        };\addlegendentry{0 g/L NaCl}

        \addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit ,
        ] coordinates {
            (A,17.66)+-(A,0.174355957741627)
            (B,15.4966666666667)+-(B,0.0251661147842353)
            (C,18.5066666666667)+-(C,0.173877351409934)
            (D,18.18)+-(D,0.0871779788708136)
            (E,18.4966666666667)+-(E,0.0776745346515396)
        };\addlegendentry{0.05 g/L NaCl}
\addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit ,
        ] coordinates {
            (A,19.01)+-(A,0.156204993518134)
            (B,18.7266666666667)+-(B,0.11503622617825)
            (C,19.07)+-(C,0.112694276695846)
            (D,18.39)+-(D,0.0871779788708136)
            (E,18.7233333333333)+-(E,0.11503622617825)
        }; \addlegendentry{0.5 g/L NaCl}
\addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit ,
        ] coordinates {
            (A,19.5)+-(A,0.219317121994613)
            (B,18.6933333333333)+-(B,0.0602771377334176)
            (C,19.2866666666667)+-(C,0.0251661147842344)
            (D,19.4766666666667)+-(D,0.0680685928555417)
            (E,19.1866666666667)+-(E,0.0404145188432747)
        }; \addlegendentry{5 g/L NaCl}
\addplot+ [
            error bars/.cd,
                y dir=plus,
                ymode=log,
                y explicit ,
        ] coordinates {
            (A,65)+-(A,8)
            (B,64.5633333333333)+-(B,4.27418218298347)
            (C,68.3033333333333)+-(C,0.733303029676911)
            (D,68.02)+-(D,0.347706773014274)
            (E,72)+-(E,2.80770962411239)
        };\addlegendentry{50 g/L NaCl}
    \end{axis}
\end{tikzpicture}
\label{sizeHS}
\caption{Particle Size Ludox HS}
\end{figure}

As you can see the last one is pretty big respect to the others thanks!!

2
  • There are errors in your code: if you have ymode=log,, you cannot have ymin=0, and ymode=log, is not a valid key after error bars/.cd,. BTW, if you use the code from the answer of your previous question, please consider accepting the answer by clicking on the check mark left of it. – user194703 Dec 1 '19 at 0:05
  • BTW, your problem can be solved with with either axis discontinuities (see section 4.9.12 Axis Discontinuities) and/or user transformations (see section 4.21 Symbolic Coordinates and User Transformations). – user194703 Dec 1 '19 at 0:07
1

Your question is very similar to this one. Since I have the data and so on from my previous answer, I put an answer here.

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathmorphing}
\pgfplotsset{compat=1.16,
/pgfplots/broken ybar legend/.style={
/pgfplots/legend image code/.code={
\draw [##1,/tikz/.cd,bar width=3pt,yshift=-0.2em,bar shift=0pt,yscale=2]
plot coordinates {(0cm,0.8em) (2*\pgfplotbarwidth,0.6em)};
\fill[white,decoration={zigzag,segment length=1pt,amplitude=0.3pt}]
(-1.7pt,0.4em) -- (-1.7pt,0.5em) decorate{-- (1.7pt,0.5em)} --  (1.7pt,0.4em)
decorate{-- (-1.7pt,0.4em)};
},
},}
\begin{document}
\begin{figure}[h]
\centering
\begin{tikzpicture}[pics/axis dicontinuity/.style={code={
    \fill[white] (-0.21,-0.5) rectangle (0.21,0.5);
    \draw (0,-0.6) -- (0,-0.4) -- ++ (0.2,0.2) -- ++(-0.4,0.4) 
    -- ++ (0.2,0.2) -- (0,0.6);}},
    pics/bar discontinuity/.style={code={
    }}]
    \begin{axis}[legend pos=outer north east,
        width=12cm, 
        ybar,
        bar width=7pt,
        xlabel=pH,
        symbolic x coords={A,B,C,D,E},
        xtick={A,B,C,D,E},
        xticklabels={10,7.5,5.2,3.8,3.0},
        ylabel=Size (d.nm),
        enlarge x limits={0.2},
        ytick={0,5,10,15,20,30,35,40},
        yticklabels={0,5,10,15,20,60,70,80},
        ymin=0,ymax=40,
        ymajorgrids=true,
        scaled ticks=false,
        xtick style={
            /pgfplots/major tick length=0pt,
        }
    ]
        \addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit ,
        ] coordinates {
            (A,15.23)+-(A,0.0346410161513768)
            (B,16.8466666666667)+-(B,0.14224392195568)
            (C,18.1166666666667)+-(C,0.187705443004015)
            (D,18.6866666666667)+-(D,0.14571661996263)
            (E,18.4033333333333)+-(E,0.117189305541646)
        };\addlegendentry{0 g/L NaCl}

        \addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit ,
        ] coordinates {
            (A,17.66)+-(A,0.174355957741627)
            (B,15.4966666666667)+-(B,0.0251661147842353)
            (C,18.5066666666667)+-(C,0.173877351409934)
            (D,18.18)+-(D,0.0871779788708136)
            (E,18.4966666666667)+-(E,0.0776745346515396)
        };\addlegendentry{0.05 g/L NaCl}
\addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit ,
        ] coordinates {
            (A,19.01)+-(A,0.156204993518134)
            (B,18.7266666666667)+-(B,0.11503622617825)
            (C,19.07)+-(C,0.112694276695846)
            (D,18.39)+-(D,0.0871779788708136)
            (E,18.7233333333333)+-(E,0.11503622617825)
        }; \addlegendentry{0.5 g/L NaCl}
\addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit ,
        ] coordinates {
            (A,19.5)+-(A,0.219317121994613)
            (B,18.6933333333333)+-(B,0.0602771377334176)
            (C,19.2866666666667)+-(C,0.0251661147842344)
            (D,19.4766666666667)+-(D,0.0680685928555417)
            (E,19.1866666666667)+-(E,0.0404145188432747)
        }; \addlegendentry{5 g/L NaCl}
\addplot+ [yscale=0.5,broken ybar legend,
            error bars/.cd,
                y dir=plus,
                %ymode=log,
                y explicit ,
        ] coordinates {
            (A,65)+-(A,8)
            (B,64.5633333333333)+-(B,4.27418218298347)
            (C,68.3033333333333)+-(C,0.733303029676911)
            (D,68.02)+-(D,0.347706773014274)
            (E,72)+-(E,2.80770962411239)
        };\addlegendentry{50 g/L NaCl}
    \path (axis description cs:0,0.6) coordinate (L) (axis description cs:1,0.6) coordinate (R);    
    \end{axis}
    \path (L) pic {axis dicontinuity} (R) pic {axis dicontinuity};
    \fill[white,decoration={zigzag,segment length=1mm,amplitude=0.4mm}]
    ([xshift=2.5mm,yshift=-1mm]L) -- ++ (0,2mm)
    decorate{-- ([xshift=-2.5mm,yshift=1mm]R)}
    -- ++(0,-2mm) decorate{-- cycle};
\end{tikzpicture}
\label{sizeHS}
\caption{Particle Size Ludox HS}
\end{figure}
\end{document}

enter image description here

Please note also that your code has errors and that one exchanges codes on this site via minimal working examples. Also, if one decides to use a code that one has gotten from an answer, one should at least indicate the source, and consider to accept the answer if it solved the problem posed in the corresponding question.

2
  • Thank you! I have been looking at the code but I haven't figured out how you solve the scale of the purple bars. I mean, I have another plot similar to this one but the longest bar is around 9000 and the shortest around 1000. So I am trying by changing ticks and scale as you did but without success. Could you please explain me? – Jhonnatan Rodriguez Dec 2 '19 at 12:59
  • @JhonnatanRodriguez The trick is to use yscale=0.5 for the purple bars. Of course, the scale factor depends on the problem, but here 0.5 looks fine IMHO. – user194703 Dec 2 '19 at 15:04

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.