I have this code:



\definecolor{trolleygrey}{rgb}{0.5, 0.5, 0.5}
\definecolor{darkgray}{rgb}{0.66, 0.66, 0.66}

\author{antonis.makris2411 Mak}
\date{July 2019}



    /pgfplots/bar shift auto/.style={
        /pgf/bar shift={
        + (int(3/2*\numplotsofactualtype-1))*(#1))  +
          + \plotnumofactualtype*(#1)
    A bar/.style={nodes near coords={\stepcounter{cheat}%
    B bar/.style={darkgray,fill=darkgray,mark=none}
        width  = 0.9*\textwidth,
        major x tick style = transparent,
        bar width=0.4cm,
        ymajorgrids = true,
        ylabel = {Response Time (sec)},
        symbolic x coords={P1,P2},
        xtick = data,
        scaled y ticks = false,
        enlarge x limits=0.35,
        x tick label style={font=\Large,yshift=-10pt},
        y tick label style={font=\Large},
        y label style={font=\Large},
        legend cell align=left,
        legend style={font=\Large,draw=none, legend columns=-1},
        visualization depends on=y \as \rawy,
        every node near coord/.append style={% https://tex.stackexchange.com/a/110887/121799
                    shift={(axis direction cs:P1,-\rawy)}

        \addplot[A bar]
            coordinates {(P1, 104.09) (P2,685.37)};
        \addplot[B bar]
            coordinates {(P1, 103.43) (P2,364.37)};

        \addplot[A bar]
              coordinates {(P1,495.74) (P2,454.20)};
        \addplot[B bar]
            coordinates {(P1, 364.43) (P2,364.37)};

        \addplot[A bar]
           coordinates {(P1,1929.74) (P2,454.20)};
        \addplot[B bar]
              coordinates {(P1,699.54) (P2,454.20)};

        \legend{S1, S2}
  \end{tikzpicture}% pic 1

that produces this:

enter image description here

This chunk of code:

        /pgfplots/bar shift auto/.style={
            /pgf/bar shift={
            + (int(3/2*\numplotsofactualtype-1))*(#1))  +
              + \plotnumofactualtype*(#1)

sets the distance between pairs of bars P1-10, P1-100, P1-1000.

Because I am new to pgfplots I dont know how to increase this distance. Which value to change?

  • I am not sure, which distance you want to increase. Either: Between each of the two plots of one pair, e.g. P1-10 left and P1-10 right or P1-10 and P1-100 &P1-100 & P1-1000...? – oerpli Jul 16 '19 at 8:49
  • I recommend using plain TikZ only – Black Mild Jul 16 '19 at 8:55
  • Hello @oerpli. The second one. – Telperinquar Jul 16 '19 at 12:38

Use this definition instead:

    /pgfplots/bar shift auto/.style={
        /pgf/bar shift={
        - \distb * \dista * 0.5*(int(3/2*\numplotsofactualtype-1)*\pgfplotbarwidth
        + \distb          * (int(3/2*\numplotsofactualtype-1))*(#1))
        + \distb * \dista * (.5+\plotnumofactualtype+int(\plotnumofactualtype/2))*\pgfplotbarwidth
        + \distb          * \plotnumofactualtype*(#1)

It has two additional 'parameters' (actually globally defined macros), distb and dista.

Put this above the tikzpicture:


One increases the distance between the dark and lighter gray plot, the other between pairs of those. Find values for both that suit your preferences, as I am not quite sure, what you're going for.

I didn't get the bar shift auto function completely - my modified version is based on my (a bit limited) understanding.

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.