Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #3421 > unrolled thread

using stats on two column data file

Started bystuart.kendrick.sea@gmail.com
First post2016-10-23 06:33 -0700
Last post2016-10-23 16:14 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.graphics.apps.gnuplot


Contents

  using stats on two column data file stuart.kendrick.sea@gmail.com - 2016-10-23 06:33 -0700
    Re: using stats on two column data file Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2016-10-23 16:14 +0200

#3421 — using stats on two column data file

Fromstuart.kendrick.sea@gmail.com
Date2016-10-23 06:33 -0700
Subjectusing stats on two column data file
Message-ID<76ee42f2-e398-432a-8c49-88a2648d83a1@googlegroups.com>
I can use stats successfully on a data file consisting of a single column but not in a file with two columns.  Suggestions on how to figure out what I am fumbling?


GOOD
cat data1.file
 95
 474
 93
 320
 425
 80
[...]

cat data1.gp
[...]
stats input_file index 0 using 1
[...]
plot input_file index 0 using 0:1 title '' with points pointtype 7 pointsize 1 l
inecolor rgb "blue", STATS_median title " Median" linecolor rgb "green", STATS_m
ean title " Mean " linecolor rgb "purple"

I see output which I believe:
cat data.gp | gnuplot
[...]
Minimum:            1.0000 [ 16]
  Maximum:        10394.0000 [132]
  Quartile:          54.0000 
  Median:           201.0000 
  Quartile:         670.0000 


BAD
However.  When I add a second column, in this case a time stamp (Year-month-day Hour), I quit believing the results:

cat data2.file
2015-10-25 14, 95
2015-10-30 04, 474
2015-11-01 12, 93
2015-11-01 13, 320
2015-11-01 14, 425
2015-11-01 15, 80
[...]

cat data2.gp
[...]
stats input_file index 0 using 2
...]
# Time formatting
set xdata time
set timefmt "%Y-%m-%d %H"
set mxtics 24
set grid mxtics
[...]
plot input_file index 0 using 1:2 title '' with points pointtype 7 pointsize 1 l
inecolor rgb "blue", STATS_median title " Median" linecolor rgb "green", STATS_m
ean title " Mean " linecolor rgb "purple"

cat data2.gp | gnuplot
[...]
  Minimum:            0.0000 [ 86]
  Maximum:           23.0000 [603]
  Quartile:           7.0000 
  Median:            12.0000 
  Quartile:          16.0000 

In the statistics above, Maximum is clearly inaccurate -- the snippet of data file which I display suggests that the Maximum would be at least 474, rather than '23' which the stats feature calculates.

Pointers?

--sk


cat data2.gp
# gnuplot configuration file, events by date and hour
#
#
# V      Who       When        What
# ---------------------------------------------------------------------------
# 1.0.0  skendric  2016-10-23  First version
#
#

# Define variables
long_title  = "ARP-4-OWN_SRCMAC / dc-a-rtr"
input_file  = "data2.file"
output_file = "data2.png"

# Exit cleanly if this install of gnuplot does not support stats
if (!strstrt(GPVAL_COMPILE_OPTIONS,"+STATS")) {
    print "No support for stats command"
    exit
}


# Chart details
set title long_title
set title long_title
set terminal png size 3200,1200
set grid
set xlabel "Date"
set ylabel "Count"

# Calculate statistics
stats input_file index 0 using 2

# http://www.phyast.pitt.edu/~zov1/gnuplot/html/statistics.html
# ToDo:  How to add shading to show stddev?

# Figure out where to put the labels
line_width = (STATS_max - STATS_min) / 25
y_offset   = STATS_records * .1

# Stats labels
set label 1 sprintf("Minimum = %.2f", STATS_min)    at y_offset, STATS_min   + l
ine_width*5 front
set label 2 sprintf("Maximum = %.2f", STATS_max)    at y_offset, STATS_min   + l
ine_width*4 front
set label 3 sprintf("Mean = %.2f"   , STATS_mean)   at y_offset, STATS_min   + l
ine_width*3 front
set label 4 sprintf("Median = %.2f",  STATS_median) at y_offset, STATS_min   + l
ine_width*2 front
set label 5 sprintf("Stdev= %.2f",    STATS_stddev) at y_offset, STATS_min   + l
ine_width*1 front

# Time formatting
set xdata time
set timefmt "%Y-%m-%d %H"
set mxtics 24
set grid mxtics

# File specifics
set datafile sep ','
set output output_file

# Do the work
plot input_file index 0 using 1:2 title '' with points pointtype 7 pointsize 1 linecolor rgb "blue", STATS_median title " Median" linecolor rgb "green", STATS_mean title " Mean " linecolor rgb "purple"

[toc] | [next] | [standalone]


#3422

FromHans-Bernhard Bröker <HBBroeker@t-online.de>
Date2016-10-23 16:14 +0200
Message-ID<e73uueFjnnhU1@mid.dfncis.de>
In reply to#3421
Am 23.10.2016 um 15:33 schrieb stuart.kendrick.sea@gmail.com:

> I can use stats successfully a data file consisting of a single
> column but not in a file with two columns. Suggestions on how to figure
> out what I am fumbling?

The key to the mystery is that, as far as you've told gnuplot by the 
time your script issues the 'stat' command, that data file has not 2, 
but 3 columns:

> 2015-10-25 14, 95
> 2015-10-30 04, 474
> 2015-11-01 12, 93
> 2015-11-01 13, 320
> 2015-11-01 14, 425
> 2015-11-01 15, 80

If you want 'stats' to treat that as a 2-column file, you have to
place this:

 > # File specifics
 > set datafile sep ','

_before_ the stats command.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.graphics.apps.gnuplot


csiph-web