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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having trouble replicating this graph


I know it's silly to do a graph with so little info, but my teacher demands it.. go figure...

I can't seem to make the bars stick together. It's my first attempt at TikZ ever...

what I've done so far:

     \begin{axis}[ symbolic x coords={18S, HNF1, Normalização dos valores para 18S}, xtick=data]  
    \addplot[ybar,fill=black] coordinates { 
      (Normalização dos valores para 18S,80) 
    \addplot[ybar,fill=gray] coordinates { 
      (Normalização dos valores para 18S, 100) 
share|improve this question
Could you please post what you have so far. That way we don't have to start from scratch. – Caramdir Feb 19 '11 at 23:56
\begin{tikzpicture} \begin{axis}[ symbolic x coords={18S, HNF1, Normalização dos valores para 18S}, xtick=data] \addplot[ybar,fill=black] coordinates { (18S,42) (HNF1,50) (Normalização dos valores para 18S,80) }; \addplot[ybar,fill=gray] coordinates { (18S,50) (HNF1,30) (Normalização dos valores para 18S, 100) }; \end{axis} \end{tikzpicture} this is more or less the example in the manual, I've been wrapping my head around the manual for some time now, guess this will take some time and patience – Santiago Feb 20 '11 at 0:33
Santiago, you should make this into a complete small document (with a \documentclass{article} and begin{document} etc.) and edit your question to include it, instead of adding the code as a comment. – Alan Munn Feb 20 '11 at 0:46
up vote 8 down vote accepted

There are a number of issues with the code you posted:

  • By specifying ybar in each \addplot command, you cause the bars to be put on top of each other. Specify the ybar once in the \axis command.
  • the ybar (or xbar) allows a value which determines the separation between bars at the same x (or y) tick. Set this to 0 to get the bars adjacent.
  • Symbolic axes don't like accented characters as far as I can tell. So the way around this problem (which also makes entering the data easier), is to use an arbitrary symbolic label like {A,B,C} and then use xticklabels to supply the labels. This also allows you to put the long label into a tabular environment, so it will wrap correctly.)
  • To get the long label to fit you need to enlarge the limits.

Here's a new version of your plot: (by the way, your numbers don't match your picture!)


  \begin{axis}[ybar=0,symbolic x coords={A, B, C}, xtick=data,
   xticklabels={18S, HNF1, \begin{tabular}{c}Normalização\\dos valores\\
   para 18S\end{tabular}},enlargelimits=0.3]  
    \addplot[fill=black] coordinates { 
    \addplot[fill=gray] coordinates { 
      (C, 100) 


enter image description here

share|improve this answer
Thank you very much! you saved my essay with that 0 hehe. I think I can do the rest.. thanks again :D – Santiago Feb 20 '11 at 2:25
@Santiago I hope your essay wasn't "reproduce this graph using tikZ" :-) Since the answer solved your problem you should click on the checkmark icon to accept the answer. – Alan Munn Feb 20 '11 at 2:43
I wish... and sorry, I'm new here and am still getting familiar with the interface. thanks again ;) – Santiago Feb 20 '11 at 2:46
@Santiago No need to apologize, and welcome. It's sometimes good to wait for a few answers before accepting an answer anyway, since there may be multiple good answers to certain questions. But in this case I think your problem was solved quite directly. Accepting answers is very helpful to others who might have a similar question since they can quickly see that the answer worked. – Alan Munn Feb 20 '11 at 2:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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