3

On the page 480 of this doc http://pgfplots.sourceforge.net/pgfplots.pdf of the pgfplots package, it talks about of how we can construct histograms from data, and says that "Then, it creates the N + 1 coordinates (xi; yi)... where yi=bincount([xi; xi+1))"... The points (xi; yi) determines the rectangles of the histogram.

So my question is :

What's the procedure used to define the intervals [xi; xi+1), and after compute the frequencies of each one of these intervals ?

More precisely, on the first example given, how this command

\addplot+[hist={bins=3}]
table[row sep=\\,y index=0] {
data\\
1\\ 2\\ 1\\ 5\\ 4\\ 10\\
7\\ 10\\ 9\\ 8\\ 9\\ 9\\
};

determines the intervals 1-4,4-7,7-10 with the respective frequencies 3,2,7?

I searched for this command "bincount", and it seems that it's a python command, which I'm not a user, so I'm searching for a solution using only Latex.

To be more precise, I want an output in form of tabular: for the example cited, it will be in this form: enter image description here

1

maybe I'm missing something here, but in your example (which is the example given in the pgfplots guide), the range is [1,10] and you have three bins: 1-4 (so includes values 1,2 and 3 if it was present), 4-7 (includes 4 to 6) etc.

  • Sorry, I should have also pointed to : 'The bins are half-open intervals, i.e. the end-point does not belong to the bin. Only the last bin contains its right end point.' – Steve Hodgkinson May 11 '16 at 10:28
  • Sorry, but what you wrote is not an answer of my problem. I want to know about the algorithm which computed the Range to 9, the length of each interval to Range/3, and computed the frequency of each interval for making the histogram – Faouzi Bellalouna May 11 '16 at 11:58
  • 1
    @FaouziBellalouna: What do you mean by "algorithm"? It's really straightforward: PGFPlots finds the min and max of all values provided in the data, that's the range. It then splits that range into a number of bins, provided by the bins parameter. These bins have equal widths, so the width of a single bin is just range/number_of_bins. It then goes through all data points, checks into which bin that point falls, and increases the count of that bin by 1. The code can be found at sourceforge.net/p/pgfplots/code/ci/master/tree/tex/generic/…. – Jake May 11 '16 at 12:26
  • @jake I was pondering on whether to link exactly the same doc, but then I thought like you that it was fairly clear in the original description! – Steve Hodgkinson May 11 '16 at 12:36
  • @Jake First sorry for some late because of a bug on my mail, which put the info of the site in spams ! Thanks for this doc. I was searching for something like this. More precisely: Where pgfplots "finds the min and max of all values provided in the data" and computes the range...where it determines the bins and the frequency of each bin (so the number of items in each bin).. with the histogram, I want the tabular of the data... (bins,frequencies) .. Thanks – Faouzi Bellalouna May 16 '16 at 13:59

Your Answer

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

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