# TikZ: Problem in overlaying a bar plot to existing bar plot

I have created a normalized histogram by the following code using tikzpicture

\begin{tikzpicture}
\begin{axis}[
width=\figurewidth,
height=\figureheight,
scale only axis,
xmode=log,
ymode=log,
ybar interval,
x tick label as interval=false,
xlabel = {$\boldsymbol{\nabla}\cdot{\bf u}_{int}$},
xtick={},
xtickten={-18,-16,...,4},
yticklabels={$0.0001\%$, $0.001\%$, $0.01\%$, $0.1\%$, $1\%$, $10\%$, $100\%$},
xmin=1e-17, xmax=1e+4,
ymin=1e-5,ymax=1,
grid=none,
ymajorgrids,
]
\addplot [fill=gray!90] table [x=Lower, y=Count] {
Lower Upper Count
9.9e-15 1e-14      0.1231
1e-14   1e-13      1e-15
1e-13   1e-12      0.0000
1e-12   1e-11      0.0000
1e-11   1e-10      0.0000
1e-10   1e-9       0.0000
1e-9    1e-8       0.0000
1e-8    1e-7       0.0001
1e-7    1e-6       0.0001
1e-6    1e-5       0.0004
1e-5    1e-4       0.0010
1e-4    1e-3       0.0048
1e-3    1e-2       0.0313
1e-2    1e-1       0.1562
1e-1    1e+0       0.3464
1e+0    1e+1       0.2684
1e+1    1e+2       0.0645
1e+2    1e+3       0.0036
1e+3    1e+4       1e-15
};
\end{axis}
\end{tikzpicture}


This will create a figure like the following:

I have tried to overlay another histogram to the figure by adding the following code.

\addplot [fill=gray!50] table [x=Lower, y=Count] {
Lower Upper Count
1e-16 1e-15 1
};


Unfortunately, after adding the above code I will end up having the following figure.

I only want to overlay the second dataset to the existing histogram without introducing any gap between the bars. A figure similar to the following where the red bar represents the second dataset (this figure is made by myself in Photoshop not by TikZ):

Could someone help me solve this problem?

-
The MWE is firstly incomplete as you do not state which version of pgfplots is used and also I was not able to generate the first plot using the code provided (compat=1.7). – devendra Jan 10 '13 at 2:32
I don't know how to find the version. But I was able to find the date for the package, which is 2010-08-09. Does this help? – Ahmad Jan 10 '13 at 2:50
Put \listfiles in your preamble and look at the version of pgfplots in the .log file. But I can say that you have a very old version. I suggest that you update it. – hpesoj626 Jan 10 '13 at 3:11
@Ahmad It is recommended practice for pgfplots to use \usepackage{pgfplots} \pgfplotsset{compat=1.7} where 1.7 is the version number. Your installation sounds very old. Please update. You can also look the accompanying pgfplots manual which will clearly state the version you are using. Also, the MWE should be something which a person can compile without any modification. Something like the answer provided by Jake to your earlier question including documentclass, packages and \begin{document} statements. – devendra Jan 10 '13 at 3:45
I used \listfiles and the version I am using is 1.4.1. I am going to update it. – Ahmad Jan 10 '13 at 3:46

If you want to have several ybar intervals in the same axis, you need to provide the ybar interval keyword to the individual \addplot commands, otherwise PGFPlots will introduce a shift between the bars to make sure both plots are visible.

Also note that the ybar interval style does not use the values you provide in the Upper column to determine how wide the bars should be, but instead it uses two consecutive Lower values. That means that you always need to provide an extra data row at the end of your table to determine how wide the last bar should be:

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.7}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
scale only axis,
xmode=log,
ymode=log,
x tick label as interval=false,
xtick={},
xtickten={-18,-16,...,4},
yticklabels={$0.0001\%$, $0.001\%$, $0.01\%$, $0.1\%$, $1\%$, $10\%$, $100\%$},
xmin=1e-17, xmax=1e+4,
ymin=1e-5,ymax=1,
grid=none,
ymajorgrids,
log origin=infty,
bar shift=0pt
]
ybar interval] table [x=Lower, y=Count] {
Lower Upper Count
9.9e-15 1e-14      0.1231
1e-14   1e-13      1e-15
1e-13   1e-12      0.0000
1e-12   1e-11      0.0000
1e-11   1e-10      0.0000
1e-10   1e-9       0.0000
1e-9    1e-8       0.0000
1e-8    1e-7       0.0001
1e-7    1e-6       0.0001
1e-6    1e-5       0.0004
1e-5    1e-4       0.0010
1e-4    1e-3       0.0048
1e-3    1e-2       0.0313
1e-2    1e-1       0.1562
1e-1    1e+0       0.3464
1e+0    1e+1       0.2684
1e+1    1e+2       0.0645
1e+2    1e+3       0.0036
1e+3    1e+4       1e-15
};
\addplot [fill=red!50, ybar interval] table [x=Lower, y=Count] {
Lower Count
1e-16 1
1e-15 1
};
\end{axis}
\end{tikzpicture}
\end{document}

-