Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
   \documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title = {ring enrich.},
ybar,
width=10cm,
xtick={1,2},
xticklabels={%
    before,
    after,
}]
\addplot[
   fill=blue!25,
   draw=black,
   error bars/.cd,
   y dir=both,
   y explicit
] 
table [y error=error] {
x   y       error
1   6.63    3.95
};

\addplot[
   fill=red!25,
   draw=black,
   error bars/.cd,
   y dir=both,
   y explicit
] 
table [y error=c] {
x   y       c
2   41.58   8.48
};

\end{axis}
\end{tikzpicture}
\end{document}
share|improve this question

closed as too localized by Jake, lockstep, Claudio Fiandrino, Kurt, Paul Gaborit Feb 7 '13 at 12:52

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}) or select your code and hit Ctrl+K. –  Claudio Fiandrino Feb 7 '13 at 9:56
    
Thanks, the comma thing was my oversight. Even though I haven't understood why changing xbar to ybar solves the problem. –  Maril Feb 7 '13 at 10:29
    
Also may I ask for another problem? I've got another simpler bar plot. the problem is bars are too far from each other, what can I do? –  Maril Feb 7 '13 at 10:30
    
'\documentclass{standalone} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis}[ title = {ring enrich.}, ybar, width=10cm, barwidth=5pt, xtick={1,2}, xticklabels={% before, after, }] \addplot[ fill=blue!25, draw=black, ybar, error bars/.cd, y dir=both, y explicit ] table [y error=error] { x y error 1 6.63 3.95 }; \addplot[ fill=red!25, draw=black, ybar, error bars/.cd, y dir=both, y explicit ] table [y error=c] { x y c 2 41.58 8.48 }; \end{axis} \end{tikzpicture} \end{document}' –  Maril Feb 7 '13 at 10:33
    
sorry don't know how to insert a code in the comment! –  Maril Feb 7 '13 at 10:40
show 4 more comments

1 Answer

You can move the bars closer while keeping the overall plot width constant by setting enlarge x limits=<value>, where <value> specifies by what fraction you want to increase the axis range. To make the bars wider, you can set bar width=<width>:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar, bar shift=0pt,
bar width=1cm,
enlarge x limits=0.5,
width=10cm,
xtick={1,2},
]
\addplot[
   fill=blue!25,
   draw=black
] 
table{
x   y       error
1   6.63    3.95
};

\addplot[
   fill=red!25,
   draw=black
] 
table {
x   y       c
2   41.58   8.48
};

\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
perfect, thank you –  Maril Feb 7 '13 at 14:15
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.