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.

I want to make a chart with nine bars. As you can see they are in the code (0-8). Unfortunately it's making only eight bars.

\documentclass[12pt]{report}
\usepackage{polski}
\usepackage{pgfplots,tikz}
\pagestyle{empty}
\pgfplotsset{width=14cm,compat=1.3}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Prawdopodobieństwo,
enlargelimits=0.02,
legend style={at={(0.5,-0.15)},
anchor=north,legend=-1},
ybar interval=0.8,
]
\addplot 
coordinates{
(0,0.00390625)
(1,0.03125)
(2,0.109375)
(3,0.21875)
(4,0.273438)
(5,0.21875)
(6,0.109375)
(7,0.03125)
(8,0.00390625)
};
\addplot 
coordinates{
(0,0.00405)
(1,0.03143)
(2,0.10847)
(3,0.21984)
(4,0.2723)
(5,0.2166)
(6,0.11272)
(7,0.03062)
(8,0.00397)
};
\addplot 
coordinates{
(0,0.00261035)
(1,0.0237304)
(2,0.107973)
(3,0.221879)
(4,0.270052)
(5,0.22449)
(6,0.108685)
(7,0.0363075)
(8,0.00427148)
};
\legend{Rozklad teoretyczny,Rozklad dla n=100000,Rozklad dla n=4214}
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

This works for me if I change ybar interval=0.8 to just ybar and remove enlargelimits=0.02. I guess you may need to adjust the settings a little more carefully starting from a working plot and going toward what you want.

share|improve this answer
add comment

If you want to use the ybar interval style, you need to supply an extra "dummy datapoint" to each plot. This is necessary because the interval style is used for plotting bars over ranges, not at points, so in order to calculate the width of the last range, you need to supply an upper limit.

\documentclass[12pt]{report}
\usepackage{polski}
\usepackage{pgfplots,tikz}
\pagestyle{empty}
\pgfplotsset{width=14cm,compat=1.3}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar interval,
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Prawdopodobieństwo,
enlargelimits=0.02,
legend style={at={(0.5,-0.15)},
anchor=north,legend=-1},
]
\addplot 
coordinates{
(0,0.00390625)
(1,0.03125)
(2,0.109375)
(3,0.21875)
(4,0.273438)
(5,0.21875)
(6,0.109375)
(7,0.03125)
(8,0.00390625)
(9,0)
};
\addplot 
coordinates{
(0,0.00405)
(1,0.03143)
(2,0.10847)
(3,0.21984)
(4,0.2723)
(5,0.2166)
(6,0.11272)
(7,0.03062)
(8,0.00397)
(9,0)
};
\addplot 
coordinates{
(0,0.00261035)
(1,0.0237304)
(2,0.107973)
(3,0.221879)
(4,0.270052)
(5,0.22449)
(6,0.108685)
(7,0.0363075)
(8,0.00427148)
(9,0)
};
\legend{Rozklad teoretyczny,Rozklad dla n=100000,Rozklad dla n=4214}
\end{axis}
\end{tikzpicture}
\end{document}

ybar interval plot

Alternatively, you can just use the ybar style. In that case, you should use enlarge y limits=0.02 instead of enlargelimits=0.02 to make sure that no bars are cut off at the sides. Notice especially the difference in the tick marks and the vertical dividing lines in the resulting plot.

ybar plot

share|improve this answer
add comment

Your Answer

 
discard

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.