8

I have a following chart, and I am trying to decrease the distance between the x-axis ticks FCC and Beta pi. Any suggestions on how to reduce this?

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

\begin{document}
\begin{tikzpicture}
\begin{axis}[
%legend columns=-1,
legend cell align=left,
every axis plot post/.style={/pgf/number format/fixed},
ybar=2pt,
bar width=10pt,
x=5cm,
y=4.5cm,
ymin=0,
axis on top,
%ymax=12,
xtick=data,
%xlabel=Cores,
ylabel=Peak Energy (E),
enlarge x limits=0.2,
%enlarge y limits={abs=0.5},
symbolic x coords={FCC,Beta pi},
%restrict y to domain*=0:11, % Cut values off at 14
visualization depends on=rawy\as\rawy, % Save the unclipped values
after end axis/.code={ % Draw line indicating break
\draw [ultra thick, white] (rel axis cs:0,1.05) -- (rel axis cs:1,1.05);
    },
nodes near coords={\scriptsize{\pgfmathprintnumber{\rawy}}
    },
axis lines*=left,
clip=false,
area legend
%legend style={at={(0.6,0.8)},anchor=west}
]
\addplot[fill=red!40] coordinates {(FCC,0.7) (Beta pi,0.66) };
\addplot[fill=yellow!40] coordinates {(FCC,1) (Beta pi,0.81) };
\addplot[fill=blue!40] coordinates {(FCC,0.6) (Beta pi,0.74)};
\addplot[fill=green!40] coordinates {(FCC,0.5) (Beta pi,0.7)};
\legend{x264,bodytrack,swaptions,blacksholes};
\end{axis}
\end{tikzpicture}
\end{document}

Unreasonably big empty white space

13

There are different ways of getting rid of that big empty space:

  • Decrease the overall width of the plot, moving the groups of bars closer together. You can do this by specifying a unit vector for the x axis. If you add more data, the plot will grow automatically.
  • Keep the overall width of the plot, but move the groups of bars closer together. You can do this by setting a larger enlarge x limits value. You can set this value in terms of axis units using abs=1 if you have \pgfplotsset{compat=1.8} or newer in your preamble.
  • Increase the width of the bars, which will fill the empty space between the groups of bars. You can do this using the bar width key. Note that you will also have to increase the enlarge x limits value, and you might want to remove the space within the groups of bars by setting ybar=0pt.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}


\begin{document}
\parbox{14cm}{
\pgfmathsetseed{2}
{\Large \texttt{ybar}}

\begin{tikzpicture}
\begin{axis}[
    ybar,
    ymin=0,
    samples=2,
    domain=1:2,
    xtick=data
]
\addplot {rnd};
\addplot {rnd};
\end{axis}
\end{tikzpicture}\\

{\Large \texttt{ybar, x=1cm, enlarge x limits=\{abs=0.5cm\}}}

\pgfmathsetseed{2}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    ymin=0,
    samples=2,
    domain=1:2,
    xtick=data,
    x=1cm,
    enlarge x limits={abs=0.5cm}
]
\addplot {rnd};
\addplot {rnd};
\end{axis}
\end{tikzpicture}\\

{\Large \texttt{ybar, enlarge x limits=\{abs=1\}}}

\pgfmathsetseed{2}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    ymin=0,
    samples=2,
    domain=1:2,
    xtick=data,
    enlarge x limits={abs=1}
]
\addplot {rnd};
\addplot {rnd};
\end{axis}
\end{tikzpicture}\\

{\Large \texttt{ybar=0pt, bar width=0.45, enlarge x limits=\{abs=0.5\}}}
\pgfmathsetseed{2}

\pgfmathsetseed{2}
\begin{tikzpicture}
\begin{axis}[
    ybar=0pt,
    ymin=0,
    samples=2,
    domain=1:2,
    xtick=data,
    bar width=0.45,
    enlarge x limits={abs=0.5}
]
\addplot {rnd};
\addplot {rnd};
\end{axis}
\end{tikzpicture}
}
\end{document}
| improve this answer | |

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.