7

I have a problem with pgfplots, when I try to plot some data from a file. I use the following code

\begin{figure}[p]
\centering
\begin{tikzpicture} 
  \begin{axis}[ybar interval,xtick=,width=\textwidth]

    \addplot+[hist={data=x,bins=30}]
            file {Data/Poisson/Poisson_Cs137_150.TKA};
  \end{axis}
\end{tikzpicture}
\caption[]{}
\end{figure}

Where as number of bins I used the maximum value of my dataset (containing only integers), because I want a bin for each integer. The problem is that the result is the following:

Histogram

As you can see there are some missing columns, while Matlab correctly shows the missing columns (I checked in the data set and the value 8 appears multiple times!).

Has anyone an idea of where the problem comes from?

Addendum: This is my preamble

\documentclass[%
    10pt,%
    a4paper,%
    onside,%
    headinclude,%
    footinclude,%
    BCOR5mm,%
    captions=tableheading]%
        {scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

%\usepackage[english]{babel}

\usepackage{indentfirst}

\usepackage{mathtools,amsmath}

    \renewcommand{\vec}{\mathbold}

    \DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\usepackage{booktabs}

\usepackage{pgfplots}
    \pgfplotsset{%
        compat=newest,%
        /pgf/number format/use comma,%
        /pgf/number format/1000 sep={\,},%
        /pgf/number format/min exponent for 1000 sep=4}

\usepackage[%
    output-decimal-marker={,}]
        {siunitx}

\usepackage{caption}

\usepackage{subfig}

\usepackage[%
    nochapters,%
    beramono,%
    eulermath,%
    pdfspacing,%
    listings]%
        {classicthesis}

Moreover, I'm sorry that I can't provide a MWE but I cannot reproduce the problem with an arbitrary and short data set (for data set with less bins pgfplots works correctly…)

EDIT 1: I noticed that if we count the columns starting from 0 (that is missing) the column 5 is directly over the label 5, while the column 20 is at the right of the label 20… Maybe the missing columns represents non-integer values? Is it possible?

EDIT 2: This is an MWE

\documentclass{standalone}

\usepackage{pgfplots}
    \pgfplotsset{%
        compat=newest,%
        /pgf/number format/use comma,%
        /pgf/number format/1000 sep={\,},%
        /pgf/number format/min exponent for 1000 sep=4}

\begin{document}

\begin{tikzpicture} 
    \begin{axis}[ybar,xtick=,width=\textwidth]

    \addplot+[hist={data=x,bins=30}]
            file {Data/Poisson/Poisson_Cs137_150.TKA};
\end{axis}
\end{tikzpicture}

\end{document}

And this are the data:

16
13
12
13
12
11
10
16
11
19
12
18
14
12
13
16
8
9
13
13
12
14
10
14
15
15
11
16
17
9
15
18
11
18
7
8
13
17
16
8
21
17
7
5
9
13
13
13
14
16
10
12
10
10
15
13
11
14
15
15
11
17
13
8
11
14
13
9
12
17
13
18
10
11
8
10
25
17
9
16
13
10
14
15
12
17
21
8
14
13
10
13
16
21
12
11
19
15
8
10
9
17
7
13
12
7
10
12
13
12
11
15
9
14
11
16
17
13
11
12
12
15
9
15
9
9
6
11
8
9
12
15
11
14
15
13
14
12
16
18
10
12
23
15
13
8
11
10
13
12
14
12
12
15
10
16
11
11
20
12
10
11
20
14
19
9
11
14
12
13
15
13
12
10
11
12
11
15
11
11
17
11
18
8
14
19
9
21
6
13
15
19
13
12
7
5
9
16
18
16
20
8
14
15
18
11
14
9
23
15
11
12
12
16
8
18
13
16
17
15
14
11
21
11
15
13
12
13
8
13
15
12
12
18
19
15
15
12
13
15
14
9
15
15
17
4
10
11
16
10
8
12
14
17
12
10
12
13
16
20
13
20
13
12
14
13
12
14
11
16
13
6
11
12
13
13
17
7
12
22
11
19
14
17
18
30
19
19
12
6
8
24
11
14
20
12
16
10
12
17
14
18
8
13
13
15
10
18
15
13
13
12
17
11
15
11
8
13
12
15
15
8
19
17
13
14
11
10
10
18
16
12
11
9
13
10
16
14
7
11
16
19
16
10
16
18
6
16
13
7
10
12
9
11
12
16
11
23
15
8
9
11
9
9
10
11
14
17
9
12
13
11
13
13
12
15
11
13
17
12
13
15
17
10
12
13
9
12
9
18
7
8
10
15
14
16
10
18
13
9
22
17
8
12
17
9
12
11
6
11
12
7
9
12
15
18
12
11
11
9
11
14
12
10
11
7
10
17
11
17
12
11
14
13
11
16
14
14
10
14
10
9
12
7
13
10
22
8
13
15
15
14
22
10
11
11
12
20
14
12
16
14
17
13
12
12
19
13
17
14
12
14
18
13
9
12
11
12
16
12
14
15
11
14
9
14
10
15
16
17
13
13
15
11
15
14
15
13
10
12
14
18
13
7
15
15
10
13
13
16

Finally this is the Matlab histogram with the same data: Matlab histogram

  • @Jake I tried with ybar but unfortunately I obtain the same problem. – user17895 Nov 12 '13 at 9:59
  • Then you need to provide a complete minimal example (please remove all the things that aren't necessary for reproducing the problem. The preamble you posted is much too detailed, for example.) – Jake Nov 12 '13 at 10:01
  • You need to show us the data - it could be there is none in those particular bins. – Andrew Swann Nov 12 '13 at 14:27
  • @AndrewSwann The data are a very long list… I visualized the histograms with Matlab and everything seems nice: I obtain the same histogram, but without missing histograms. I also visualized the data and number 8, for example, appears many times... – user17895 Nov 12 '13 at 21:22
  • @Jake I can try to cut the preamble, but without posting my long list of data I cannot reproduce the same problem with a small MWE... – user17895 Nov 12 '13 at 21:23
6

The problem is the number of bins you are specifying in relation to the data.

For your data the minimum value is 4 and the maximum is 30. You ask this range to be divided in to 30 intervals, so for your data these invtervals will each have length less than 1. As your data only contains integers, there is a chance that some of these bins will necessarily be empty.

You can either reduce the number of bins, or probably more relevant specify the max and min for the data range:

Sample output

\documentclass[%
    10pt,%
    a4paper,%
    onside,%
    headinclude,%
    footinclude,%
    BCOR5mm,%
    captions=tableheading]%
        {scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

%\usepackage[english]{babel}

\usepackage{indentfirst}

\usepackage{mathtools,amsmath}

    \renewcommand{\vec}{\mathbold}

    \DeclarePairedDelimiter{\abs}{\lvert}{\rvert}

\usepackage{booktabs}

\usepackage{pgfplots}
    \pgfplotsset{%
        compat=newest,%
        /pgf/number format/use comma,%
        /pgf/number format/1000 sep={\,},%
        /pgf/number format/min exponent for 1000 sep=4}

\usepackage[%
    output-decimal-marker={,}]
        {siunitx}

\usepackage{caption}

\usepackage{subfig}

\usepackage[%
    nochapters,%
    beramono,%
    eulermath,%
    pdfspacing,%
    listings]%
        {classicthesis}

\begin{document}
\begin{figure}[p]
\centering
\begin{tikzpicture} 
  \begin{axis}[ybar interval,xtick=,width=\textwidth]

    \addplot+[hist={data=x,bins=30,data max=30,data min=0}]
            file {Poisson_Cs137_150.TKA};
  \end{axis}
\end{tikzpicture}
\caption[]{}
\end{figure}
\end{document}
  • That was the problem! Thank you very much!!! – user17895 Nov 13 '13 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy