Problems with histogram examples code in manual
Michael Stewart <[email protected]> Wed, 5 Sep 2018 17:23:45 +1000
| Newsgroups | gmane.comp.graphics.gnuplot.bugs |
|---|---|
| Message-ID | <[email protected]> |
--=-=-= Content-Type: text/plain; format=flowed; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Dear gnuplot developers, I have found two problems with some example code in the "plot data=20 smooth frequency" section of the manual (page 95 in v5.2, page 90=20 for v5.0), designed to give equal-width intervals and rectangles=20 whose heights equal each interval frequency: binwidth =3D <something> # set width of x values in each bin bin(val) =3D binwidth * floor(val/binwidth) plot "datafile" using (bin(column(1))):(1.0) smooth frequency One problem is minor, one is major. The minor problem is: the histogram bins are centred 0.5*binwidth=20 to the left of where they should be. The definition of "bin()"=20 above replaces each data value with the left endpoint of the=20 interval it lands in, but then centres each interval at that=20 point. To fix the problem, simply replace the definition with bin(val) =3D binwidth * (floor(val/binwidth) + 0.5) and then each data point is replaced by the midpoint of the=20 interval it lands in. The major problem is: if there are any "empty bins", this code=20 (potentially) generates an incorrect histogram. If any midpoint in=20 the range of the data is not represented in bin(column(1)), this=20 code causes the "smooth frequency" procedure to do the wrong=20 thing. Rather than produce an empty interval at that position, it=20 makes the intervals either side wider (with endpoints halfway=20 between those midpoints that are represented. Worse, the heights=20 of those wider intervals are not adjusted appropriately, so that=20 area no longer reflects frequency in those intervals. I have attached a script and a PDF that it generates to illustrate=20 the problem with a simple example (I have v5.0 on fedora 28) which=20 does show clearly that using "floor()" with "smooth frequency" in=20 this way is problematic. Interestingly, the (experimental) "bins"=20 procedure, documented in the v5.2 manual but not available on my=20 v5.0, ostensibly does the right thing.=20 It may be that you are waiting for "bins" to be no longer=20 "experimental" before making this change, I guess that would make=20 sense. Apologies if this has already been flagged, but I couldn't=20 see it mentioned on the bug tracker page. Cheers, Michael --=-=-= Content-Type: text/plain; format=flowed; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable --=20 Michael Stewart School of Mathematics and Statistics The University of Sydney sydney.edu.au/science/maths/ut/people?who=3DM_Stewart CRICOS 00026A This email plus any attachments to it are confidential. Any=20 unauthorised use is strictly prohibited. If you receive this email in error,=20 please delete it and any attachments. --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ gnuplot-bugs mailing list [email protected] Membership management via: https://lists.sourceforge.net/lists/listinfo/gnuplot-bugs --=-=-=--