Turning a running total to a daily count - gnuplot

This feels like a basic high school math thing I've clearly forgotten. Anyhoo, I have data that looks like:
$Data << EOD
2020-08-09 4
2020-08-10 5
2020-08-11 6
2020-08-13 7
2020-08-14 8
EOD
set xdata time
set timefmt "%Y-%m-%d"
plot $Data u 1:2
Which looks like
Sidenote: Not sure why first value is not plotted... do you?
I just want to see the daily increments, like so:
$Data << EOD
2020-08-09 1
2020-08-10 1
2020-08-11 1
2020-08-13 1
2020-08-14 1
EOD
set xdata time
set timefmt "%Y-%m-%d"
plot $Data u 1:2
How do I get Gnuplot to just show the daily increments as I want, without editing the Data as I have done above? Any tips to link the points for readability would be greatly appreciated!

Edit: revised version after piecewise getting more information.
Plotting is like looping the data columns. In the code below x0 and y0 hold the previous values and x1 and y1 the current values. The daily change is (y1-y0) divided by (x1-x0) multiplied by 3600*24. Remember, in gnuplot date and time are handled internally in seconds passed from January, 1st 1970 00:00:00. Check help time/date. Also check help operations binary and serial evaluation.
Data: (Singapore.csv)
Singapore,2020-08-22 04:27:49,1.2833,103.8333,56216,27,53651,2538,Singapore,960.9009249543145,0.048029030880888
Singapore,2020-08-21 04:27:41,1.2833,103.8333,56099,27,53119,2953,Singapore,958.9010422123966,0.04812920016399579
Singapore,2020-08-20 04:27:43,1.2833,103.8333,56031,27,52810,3194,Singapore,957.7387172,0.04818761042994057
Singapore,2020-08-18 04:27:56,1.2833,103.8333,55838,27,52350,3461,Singapore,954.4397653265801,0.048354167412872955
Singapore,2020-08-17 04:27:20,1.2833,103.8333,55747,27,51953,3767,Singapore,952.884300971755,0.048433099538988646
Singapore,2020-08-16 04:27:42,1.2833,103.8333,55661,27,51521,4113,Singapore,951.414301691371,0.04850793194516807
Singapore,2020-08-15 04:27:31,1.2833,103.8333,55580,27,51049,4504,Singapore,950.0297674854277,0.04857862540482188
Singapore,2020-08-14 04:51:19,1.2833,103.8333,55497,27,50736,4734,Singapore,948.6110472497082,0.04865127844748365
Singapore,2020-08-13 04:29:15,1.2833,103.8333,55395,27,50520,4848,Singapore,946.8675597311133,0.048740861088545896
Singapore,2020-08-12 04:27:29,1.2833,103.8333,55353,27,50128,5198,Singapore,946.1496531058093,0.048777844019294345
Singapore,2020-08-11 04:35:08,1.2833,103.8333,55292,27,49609,5656,Singapore,945.10697919763,0.04883165738262316
Singapore,2020-08-10 04:34:55,1.2833,103.8333,55104,27,48915,6162,Singapore,941.8934923986508,0.048998257839721254
Singapore,2020-08-09 04:34:54,1.2833,103.8333,54929,27,48583,6319,Singapore,938.9022147932179,0.04915436290484079
Singapore,2020-08-08 04:34:53,1.2833,103.8333,54797,27,48312,6458,Singapore,936.6459368279776,0.04927277040713908
Singapore,2020-08-07 04:35:11,1.2833,103.8333,54555,27,48031,6497,Singapore,932.5094272250363,0.04949133901567226
Singapore,2020-08-06 04:35:02,1.2833,103.8333,54254,27,47768,6459,Singapore,927.364429743692,0.049765915877170344
Singapore,2020-08-05 04:34:43,1.2833,103.8333,53346,27,47454,5865,Singapore,911.8439722252184,0.05061297941738837
Singapore,2020-08-04 04:41:59,1.2833,103.8333,53051,27,47179,5845,Singapore,906.8015328332033,0.050894422348306344
Singapore,2020-08-03 04:34:35,1.2833,103.8333,52825,27,46926,5872,Singapore,902.9385114684727,0.05111216280170374
Singapore,2020-08-02 04:34:47,1.2833,103.8333,52512,27,46740,5745,Singapore,897.5883978084703,0.05141681901279708
Singapore,2020-08-01 04:36:27,1.2833,103.8333,52205,27,46491,5687,Singapore,892.3408422377969,0.051719183986208214
Singapore,2020-07-31 04:35:18,1.2833,103.8333,51809,27,46308,5474,Singapore,885.572008342075,0.05211449748113262
Singapore,2020-07-30 04:35:05,1.2833,103.8333,51531,27,46098,5406,Singapore,880.8201502031592,0.052395645339698434
Singapore,2020-07-29 04:35:11,1.2833,103.8333,51197,27,45893,5277,Singapore,875.1110832305046,0.05273746508584488
Singapore,2020-07-28 04:58:43,1.2833,103.8333,50838,27,45692,5119,Singapore,868.9746908856455,0.05310987843738935
Singapore,2020-07-27 04:35:02,1.2833,103.8333,50369,27,45521,4821,Singapore,860.958066903086,0.05360439953145784
Singapore,2020-07-26 04:35:00,1.2833,103.8333,49888,27,45352,4509,Singapore,852.736326741868,0.05412123155869147
Singapore,2020-07-25 04:47:39,1.2833,103.8333,49375,27,45172,4176,Singapore,843.967610104228,0.05468354430379747
Singapore,2020-07-24 05:30:40,1.2833,103.8333,49098,27,45015,4056,Singapore,839.2328449802002,0.05499205670292069
Singapore,2020-07-23 05:15:04,1.2833,103.8333,48744,27,44795,3922,Singapore,833.1819177097823,0.055391432791728215
Singapore,2020-07-22 04:34:42,1.2833,103.8333,48434,27,44584,3823,Singapore,827.8830830944443,0.055745963579303795
Singapore,2020-07-21 04:38:46,1.2833,103.8333,48035,27,44371,3637,Singapore,821.0629701540578,0.0562090142604351
Singapore,2020-07-20 05:34:40,1.2833,103.8333,47912,27,44086,3799,Singapore,818.9605293228108,0.056353314409751214
Singapore,2020-07-19 04:34:58,1.2833,103.8333,47655,27,43833,3795,Singapore,814.5676244965466,0.056657223796033995
Singapore,2020-07-18 04:34:45,1.2833,103.8333,47453,27,43577,3849,Singapore,811.1148354891327,0.05689840473731903
Singapore,2020-07-17 04:34:50,1.2833,103.8333,47126,27,43256,3843,Singapore,805.5254196206959,0.057293213937104785
Singapore,2020-07-16 04:44:59,1.2833,103.8333,46878,27,42988,3863,Singapore,801.2863519284253,0.0575963138359145
Singapore,2020-07-15 04:34:39,1.2833,103.8333,46630,27,42737,3866,Singapore,797.0472842361551,0.05790263778683251
Singapore,2020-07-14 04:34:46,1.2833,103.8333,46283,26,42541,3716,Singapore,791.1160080699542,0.05617613378562323
Singapore,2020-07-13 04:43:04,1.2833,103.8333,45961,26,42285,3650,Singapore,785.6120572759579,0.05656970039816366
Singapore,2020-07-12 04:34:30,1.2833,103.8333,45783,26,42026,3731,Singapore,782.5695006258608,0.056789638075268115
Singapore,2020-07-11 04:34:26,1.2833,103.8333,45614,26,41780,3808,Singapore,779.6807811097573,0.05700004384618757
Singapore,2020-07-10 04:34:24,1.2833,103.8333,45423,26,41645,3752,Singapore,776.4160152661134,0.057239724368711886
Singapore,2020-07-09 04:34:23,1.2833,103.8333,45298,26,41323,3949,Singapore,774.2793884050902,0.05739767760166012
Singapore,2020-07-08 05:33:48,1.2833,103.8333,45140,26,41002,4112,Singapore,771.5786920527565,0.057598582188746125
Singapore,2020-07-07 04:34:00,1.2833,103.8333,44983,26,40717,4240,Singapore,768.8950887153113,0.05779961318720406
Singapore,2020-07-06 04:33:57,1.2833,103.8333,44800,26,40441,4333,Singapore,765.7670669907733,0.05803571428571429
Singapore,2020-07-05 04:33:46,1.2833,103.8333,44664,26,40117,4521,Singapore,763.4424169659796,0.05821243059287121
Singapore,2020-07-04 04:33:51,1.2833,103.8333,44479,26,39769,4684,Singapore,760.280209211665,0.058454551586141774
Singapore,2020-07-03 04:33:54,1.2833,103.8333,44310,26,39429,4855,Singapore,757.3914896955614,0.05867749943579328
Singapore,2020-07-02 04:33:46,1.2833,103.8333,44122,26,39011,5085,Singapore,754.1780028965823,0.05892751915144372
Singapore,2020-07-01 04:33:52,1.2833,103.8333,43907,26,38500,5381,Singapore,750.5030046956222,0.05921607033047122
Singapore,2020-06-30 04:33:48,1.2833,103.8333,43661,26,37985,5650,Singapore,746.298123033128,0.05954971256
Singapore,2020-06-29 04:33:44,1.2833,103.8333,43459,26,37508,5925,Singapore,742.8453340257144,0.05982650314089141
Singapore,2020-06-28 04:34:04,1.2833,103.8333,43246,26,37163,6057,Singapore,739.2045218545305,0.06012116727558618
Singapore,2020-06-27 04:33:35,1.2833,103.8333,42955,26,36825,6104,Singapore,734.2304545220682,0.06052846001629612
Singapore,2020-06-26 04:33:43,1.2833,103.8333,42736,26,36604,6106,Singapore,730.4870842615553,0.0608386372145264
Singapore,2020-06-25 05:26:54,1.2833,103.8333,42623,26,36299,6298,Singapore,728.5555735791902,0.060999929615465825
Singapore,2020-06-24 04:33:28,1.2833,103.8333,42432,26,35995,6411,Singapore,725.2908077355464,0.061274509803921566
Singapore,2020-06-23 04:33:22,1.2833,103.8333,42313,26,35590,6697,Singapore,723.2567389638522,0.06144683666958145
Singapore,2020-06-22 04:33:20,1.2833,103.8333,42095,26,34942,7127,Singapore,719.5304617182275,0.06176505523221285
Singapore,2020-06-21 04:33:19,1.2833,103.8333,41833,26,34224,7583,Singapore,715.0520918175225,0.06215188965649129
Singapore,2020-06-20 04:33:19,1.2833,103.8333,41615,26,33459,8130,Singapore,711.3258145718977,0.06247747206536105
Singapore,2020-06-19 04:33:17,1.2833,103.8333,41473,26,32712,8735,Singapore,708.8986064577753,0.06269138957876208
Singapore,2020-06-18 04:33:18,1.2833,103.8333,41216,26,31938,9252,Singapore,704.5057016315112,0.06308229813664597
Singapore,2020-06-17 04:33:21,1.2833,103.8333,40969,26,31163,9780,Singapore,700.2837269541291,0.06346261807708267
Singapore,2020-06-16 04:33:09,1.2833,103.8333,40818,26,30366,10426,Singapore,697.7026817060128,0.06369738840707531
Singapore,2020-06-15 03:33:14,1.2833,103.8333,40604,26,29589,10989,Singapore,694.0447765199408,0.06403310018717367
Singapore,2020-06-14 03:33:15,1.2833,103.8333,40197,26,28808,11363,Singapore,687.0879194604487,0.06468144388884743
Singapore,2020-06-13 03:33:14,1.2833,103.8333,39850,25,28040,11785,Singapore,681.1566432942478,0.06273525721455459
Singapore,2020-06-12 05:09:52,1.2833,103.8333,39387,25,27286,12076,Singapore,673.2425774010173,0.06347271942519106
Singapore,2020-06-11 03:33:41,1.2833,103.8333,38965,25,26532,12408,Singapore,666.0293251182025,0.06416014371872193
Singapore,2020-06-10 04:07:00,1.2833,103.8333,38514,25,25877,12612,Singapore,658.3203754036302,0.06491146076751311
Singapore,2020-06-09 03:33:03,1.2833,103.8333,38296,25,25368,12903,Singapore,654.5940981580054,0.06528096929183204
Singapore,2020-06-08 03:33:22,1.2833,103.8333,37910,25,24886,12999,Singapore,647.9961944111653,0.06594566077552097
Singapore,2020-06-07 03:53:30,1.2833,103.8333,37527,25,24559,12943,Singapore,641.4495697089897,0.06661870120180137
Singapore,2020-06-06 02:33:00,1.2833,103.8333,37183,24,24209,12950,Singapore,635.5695725874534,0.06454562568915903
Singapore,2020-06-05 02:33:06,1.2833,103.8333,36922,24,23904,12994,Singapore,631.1082957016366,0.06500189588863009
Singapore,2020-06-04 02:33:14,1.2833,103.8333,36405,24,23582,12799,Singapore,622.271207004444,0.06592501030078286
Singapore,2020-06-03 02:33:13,1.2833,103.8333,35836,24,23175,12637,Singapore,612.5452815330657,0.06697176024109834
Singapore,2020-06-02 02:33:08,1.2833,103.8333,35292,24,22466,12802,Singapore,603.246681433892,0.06800408024481469
Singapore,2020-06-01 02:32:46,1.2833,103.8333,34884,23,21699,13162,Singapore,596.2727313595118,0.06593280587088636
Singapore,2020-05-31 02:32:45,1.2833,103.8333,34366,23,20727,13616,Singapore,587.418549647431,0.06692661351335623
Singapore,2020-05-30 02:32:48,1.2833,103.8333,33860,23,19631,14206,Singapore,578.7694841140084,0.06792675723567632
Singapore,2020-05-29 02:32:50,1.2833,103.8333,33249,23,18294,14932,Singapore
Singapore,2020-05-28 02:32:31,1.2833,103.8333,32876,23,17276,15577,Singapore
Singapore,2020-05-27 02:32:31,1.2833,103.8333,32343,23,16444,15876,Singapore
Singapore,2020-05-26 02:32:35,1.2833,103.8333,31960,23,15738,16199,Singapore
Singapore,2020-05-25 02:32:44,1.2833,103.8333,31616,23,14876,16717,Singapore
Singapore,2020-05-24 02:32:43,1.2833,103.8333,31068,23,13882,17163,Singapore
Singapore,2020-05-23 02:32:42,1.2833,103.8333,30426,23,12995,17408,Singapore
Singapore,2020-05-22 02:36:51,1.2833,103.8333,29812,23,12117,17672,Singapore
Singapore,2020-05-21 02:32:48,1.2833,103.8333,29364,22,11207,18135,Singapore
Singapore,2020-05-20 02:32:19,1.2833,103.8333,28794,22,10365,18407,Singapore
Singapore,2020-05-19 02:32:18,1.2833,103.8333,28343,22,9835,18486,Singapore
Singapore,2020-05-18 02:32:21,1.2833,103.8333,28038,22,9340,18676,Singapore
Singapore,2020-05-17 02:32:32,1.2833,103.8333,27356,22,8342,18992,Singapore
Singapore,2020-05-16 02:32:19,1.2833,103.8333,26891,21,7248,19622,Singapore
Singapore,2020-05-15 02:33:02,1.2833,103.8333,26098,21,5973,20104,Singapore
Singapore,2020-05-14 03:32:28,1.2833,103.8333,25346,21,4809,20516,Singapore
Singapore,2020-05-13 03:32:26,1.2833,103.8333,24671,21,3851,20799,Singapore
Singapore,2020-05-12 03:32:27,1.2833,103.8333,23822,21,3225,20576,Singapore
Singapore,2020-05-11 02:32:30,1.2833,103.8333,23336,20,2721,20595,Singapore
Singapore,2020-05-10 02:32:30,1.2833,103.8333,22460,20,2296,20144,Singapore
Singapore,2020-05-09 02:32:35,1.2833,103.8333,21707,20,2040,19647,Singapore
Singapore,2020-05-08 02:32:32,1.2833,103.8333,20939,20,1712,19207,Singapore
Singapore,2020-05-07 02:32:28,1.2833,103.8333,20198,20,1634,18544,Singapore
Singapore,2020-05-06 02:32:31,1.2833,103.8333,19410,18,1519,17873,Singapore
Singapore,2020-05-05 02:32:34,1.2833,103.8333,18778,18,1457,17303,Singapore
Singapore,2020-05-04 02:32:28,1.2833,103.8333,18205,18,1408,16779,Singapore
Singapore,2020-05-03 02:32:28,1.2833,103.8333,17548,17,1347,16184,Singapore
Singapore,2020-05-02 02:32:27,1.2833,103.8333,17101,16,1268,15817,Singapore
Singapore,2020-05-01 02:32:28,1.2833,103.8333,16169,15,1244,14910,Singapore
Singapore,2020-04-30 02:32:27,1.2833,103.8333,15641,14,1188,14439,Singapore
Singapore,2020-04-29 02:32:29,1.2833,103.8333,14951,14,1128,13809,Singapore
Singapore,2020-04-28 02:30:32,1.2833,103.8333,14423,14,1095,13314,Singapore
Singapore,2020-04-27 02:30:33,1.2833,103.8333,13624,12,1060,12552,Singapore
Singapore,2020-04-26 02:30:31,1.2833,103.8333,12693,12,1002,11679,Singapore
Singapore,2020-04-25 06:30:33,1.2833,103.8333,12075,12,956,11107,Singapore
Singapore,2020-04-24 03:30:31,1.2833,103.8333,11178,12,924,10242,Singapore
Singapore,2020-04-22 23:30:32,1.2833,103.8333,10141,12,896,9233,Singapore
Singapore,2020-04-21 23:30:30,1.2833,103.8333,9125,11,839,8275,Singapore
Singapore,2020-04-20 23:36:27,1.2833,103.8333,8014,11,801,7202,Singapore
Singapore,2020-04-19 23:40:41,1.2833,103.8333,6588,11,768,5809,Singapore
Singapore,2020-04-18 22:32:28,1.2833,103.8333,5992,11,740,5241,Singapore
Singapore,2020-04-17 23:30:32,1.2833,103.8333,5050,11,708,4331,Singapore
Singapore,2020-04-16 23:30:31,1.2833,103.8333,4427,10,683,3734,Singapore
Singapore,2020-04-15 22:56:32,1.2833,103.8333,3699,10,652,3037,Singapore
Singapore,2020-04-14 23:33:12,1.2833,103.8333,3252,10,611,2631,Singapore
Singapore,2020-04-13 23:07:34,1.2833,103.8333,2918,9,586,2323,Singapore
Singapore,2020-04-12 23:17:00,1.2833,103.8333,2532,8,560,1964,Singapore
Singapore,2020-04-11 22:45:13,1.2833,103.8333,2299,8,528,1763,Singapore
Singapore,2020-04-10 22:53:48,1.2833,103.8333,2108,7,492,1609,Singapore
Singapore,2020-04-09 23:02:19,1.2833,103.8333,1910,6,460,1444,Singapore
Singapore,2020-04-08 22:51:39,1.2833,103.8333,1623,6,406,1211,Singapore
Singapore,2020-04-07 23:04:29,1.2833,103.8333,1481,6,377,1098,Singapore
Singapore,2020-04-05 23:06:26,1.2833,103.8333,1309,6,320,983,Singapore
Singapore,2020-04-03 22:46:20,1.2833,103.8333,1114,5,282,827,Singapore
Singapore,2020-04-01 21:58:34,1.2833,103.8333,1000,3,245,752,Singapore
Singapore,2020-03-31 23:43:43,1.2833,103.8333,926,3,240,683,Singapore
Singapore,2020-03-27 23:23:03,1.2833,103.8333,732,2,183,547,Singapore
Singapore,2020-03-26 23:48:18,1.2833,103.8333,683,2,172,509,Singapore
Singapore,2020-03-25 23:33:04,1.2833,103.8333,631,2,160,469,Singapore
Singapore,2020-03-24 23:37:15,1.2833,103.8333,558,2,156,400,Singapore
Singapore,2020-03-23 23:19:21,1.2833,103.8333,509,2,152,355,Singapore
Singapore,2020-03-21T13:13:30,432,2,140,1.3521,103.8198
Singapore,2020-03-20T15:43:24,385,0,124,1.3521,103.8198
Singapore,2020-03-19T16:13:36,345,0,114,1.3521,103.8198
Singapore,2020-03-18T13:33:12,313,0,114,1.3521,103.8198
Singapore,2020-03-17T15:33:06,266,0,114,1.3521,103.8198
Singapore,2020-03-16T14:38:45,243,0,109,1.3521,103.8198
Singapore,2020-03-15T18:20:18,226,0,105,1.3521,103.8198
Singapore,2020-03-14T16:14:30,212,0,105,1.3521,103.8198
Singapore,2020-03-11T20:00:00,200,0,97,1.3521,103.8198
Singapore,2020-03-11T13:53:24,178,0,96,1.2833,103.8333
Singapore,2020-03-11T13:53:24,178,0,96,1.2833,103.8333
Singapore,2020-03-10T05:13:07,160,0,78,1.2833,103.8333
Singapore,2020-03-08T13:33:13,150,0,78,1.2833,103.8333
Singapore,2020-03-08T13:33:13,150,0,78,1.2833,103.8333
Singapore,2020-03-07T17:53:03,138,0,78,1.2833,103.8333
Singapore,2020-03-06T13:03:12,130,0,78,1.2833,103.8333
Singapore,2020-03-05T13:43:04,117,0,78,1.2833,103.8333
Singapore,2020-03-03T15:23:03,110,0,78,1.2833,103.8333
Singapore,2020-03-03T15:23:03,110,0,78,1.2833,103.8333
Singapore,2020-03-02T20:33:02,108,0,78,1.2833,103.8333
Singapore,2020-03-01T23:23:02,106,0,72,1.2833,103.8333
Singapore,2020-02-29T14:33:03,102,0,72
Singapore,2020-02-26T19:33:02,93,0,62
Singapore,2020-02-26T19:33:02,93,0,62
Singapore,2020-02-26T19:33:02,93,0,62
Singapore,2020-02-25T18:55:32,91,0,53
Singapore,2020-02-23T15:13:15,89,0,51
Singapore,2020-02-23T15:13:15,89,0,51
Singapore,2020-02-21T03:43:02,85,0,37
Singapore,2020-02-21T03:43:02,85,0,37
Singapore,2020-02-19T22:13:08,84,0,34
Singapore,2020-02-19T22:13:08,84,0,34
Singapore,2020-02-18T16:53:03,81,0,29
Singapore,2020-02-17T14:33:04,77,0,24
Singapore,2020-02-16T16:23:06,75,0,18
Singapore,2020-02-15T23:53:02,72,0,18
Singapore,2020-02-14T12:43:02,67,0,17
Singapore,2020-02-13T14:33:02,58,0,15
Singapore,2020-02-12T19:53:02,50,0,15
Singapore,2020-02-11T16:43:06,47,0,9
Singapore,2020-02-10T19:03:02,45,0,2
Singapore,2020-02-09T02:43:02,40,0,2
Singapore,2020-02-08T12:53:01,33,0,2
Singapore,2020-02-07T03:03:03,30,0,0
Singapore,2020-02-05T16:33:03,28,0,0
Singapore,2020-02-05T16:33:03,28,0,0
Singapore,2020-02-04T15:33:03,24,0,0
Singapore,2020-02-02T01:03:32,18,0,0
Singapore,2020-02-02T01:03:32,18,0,0
Be aware that your date format changes within your file. But here it is not critical.
Singapore,2020-08-22 04:27:49,1.2833,103.8333,56216,27,53651,2538,Singapore,960.9009249543145,0.048029030880888
...
Singapore,2020-02-05T16:33:03,28,0,0
Code:
### plot daily change
reset session
FILE = "Singapore.csv"
set datafile separator comma
set format x "%m/%d" timedate
x1=NaN
y1=NaN
plot FILE u (x0=x1,x1=timecolumn(2,"%Y-%m-%d")):(y0=y1,y1=$5,(y1-y0)/(x1-x0)*3600*24) \
w lp pt 7 title "Daily change"
### end of code
Result:

Related

gnuplot: histogram of events: issue with timecolumn()

I would like to see the number of events per timeperiod.
My rows look like this
"2020-11-11 09:15:50",field2,field3
This is what I have tried
binwidth = 3600 # 1h in seconds
bin(t) = (t - (int(t) % binwidth) + binwidth/2)
set datafile separator ","
#set xdata time
set timefmt '"%Y-%m-%d %H:%M:%S"'
set boxwidth binwidth
plot 'Statistics.log' using (bin(timecolumn(1, '"%Y-%m-%d %H:%M:%S"'))):(1) smooth freq with boxes
I'm getting
unknown type in magnitude()
How would I debug errors like these? (How do I dump what gnuplot "sees" for timecolumn() etc.?)
(gnuplot 4.6)
At first, The timecolumn() in gnuplot 4.6 is a single-argument function, and only the argument for the column number is allowed. Therefore, the plot command can be rewritten as,
plot "test.dat" using (bin(timecolumn(1))):(1) smooth freq with boxes
Secondly, do not include leading and trailing double quotes in your timefmt formatting.
set timefmt '%Y-%m-%d %H:%M:%S'
For more information about this, please refer to the "help data" section.
...
However, whitespace inside a pair of double quotes is ignored when
counting columns, so the following datafile line has three columns:
1.0 "second column" 3.0
Finally, your code can be modified as follows (for gnuplot 4.6)
binwidth = 3600 # 1h in seconds
bin(t) = (t - (int(t) % binwidth) + binwidth/2)
set datafile separator ","
set xdata time
set timefmt '%Y-%m-%d %H:%M:%S'
set boxwidth binwidth
plot 'Statistics.log' using (bin(timecolumn(1))):(1) smooth freq with boxes
A few minutes too late... while testing... #binzo basically already answered.
The only difference: if your data uses double quotes for the date
"2020-11-11 09:15:50",field2,field3`
and you don't want to change your existing data, you have to specify it in set timefmt. For some strange reason which I cannot explain right now, if you set datafile separator "," it will mess up the graph, but it seems to work without.
Code: (tested with gnuplot 4.6.0)
### timedata in histogram (gnuplot 4.6)
reset
FILE = 'Statistics.log'
myTimeFmt = '"%Y-%m-%d %H:%M:%S"'
# create some test data
myDate = strptime(myTimeFmt, '"2020-11-11 11:11:11"')
myRandomDate(n) = myDate + 3*3600*invnorm(rand(0))
set print FILE
do for [i=1:500] {
print sprintf("%s,%g,%g",strftime(myTimeFmt,myRandomDate(0)),rand(0),rand(0))
}
set print
# set datafile separator "," # if uncommented this will messup the plot, don't know why
set xdata time
set format x "%Y-%m-%d\n%H:%M"
set timefmt '"%Y-%m-%d %H:%M:%S"'
binwidth = 3600 # 1 h in seconds
bin(t) = (t - (int(t) % binwidth) + binwidth/2)
set boxwidth binwidth
set style fill solid 0.5
set xtics 4*3600 # 4 h in seconds
plot FILE u (bin(timecolumn(1))):(1) smooth freq w boxes notitle
### end of code
Result:

store commented value from data file in gnuplot

I have multiple data files output_k, where k is a number. The files look like
#a=1.00 b = 0.01
# mass mean std
0.2 0.0163 0.0000125
0.4 0.0275 0.0001256
Now I need to retrieve the values of a and b and to store them in a variable, so I can use them for the title or function input etc. The looping over the files in the folder works. But I need some help with reading out the the parameters a and b. This is what i have so far.
# specify the number of plots
plot_number = 100
# loop over all data files
do for [i=0:plot_number] {
a = TODO
b = TODO
#set terminal
set terminal postscript eps size 6.4,4.8 enhanced color font 'Helvetica,20' linewidth 2
set title "Measurement \n{/*0.8 A = a, B = b}"
outFile=sprintf("plot_%d.eps", i)
dataFile=sprintf("output_%d.data", i)
set output outFile
plot dataFile using 1:2:3 with errorbars lt 1 linecolor "red", f(a,b)
unset output
}
EDIT:
I am working with gnuplot for windows.
If you are on a Unixoid system, you can use system to get the output of standard command line tools, namely head and sed, which again allow to extract said values form the files:
a = system(sprintf("head -n 1 output_%i.data | sed \"s/#a=//;s/ b .*//\"", i))
b = system(sprintf("head -n 1 output_%i.data | sed \"s/.*b = //\"", i))
This assumes that the leading spaces to all lines in your question are actually a formatting mistake.
A late answer, but since you are working under Windows you either install the comparable utilities or you might be interested in a gnuplot-only solution (hence platform-independent).
you can use stats to extract information from the datablock (or file) to variables. Check help stats.
the extraction of your a and b depends on the exact structure of that line. You can split a line at spaces via word(), check help word and get substrings via substr() or indexing, check help substr.
Script: (works with gnuplot>=5.0.0)
### extract information from commented header without external tools
reset session
$Data <<EOD
#a=1.00 b = 0.01
# mass mean std
0.2 0.0163 0.0000125
0.4 0.0275 0.0001256
EOD
set datafile commentschar ''
set datafile separator "\t"
stats $Data u (myHeader=strcol(1)[2:]) every ::0::0 nooutput
set datafile commentschar # reset to default
set datafile separator # reset to default
a = real(word(myHeader,1)[3:])
b = real(word(myHeader,4))
set label 1 at graph 0.1,0.9 sprintf("a=%g\nb=%g",a,b)
plot $Data u 1:2 w lp pt 7 lc "red"
### end of script
Result:

How plot graph with missing data lines?

I have data recorded in time. But some data lines are missing and gnuplot replace them with long lines in these intervals.
How can i set gnuplot to draw nothing instead of draw lines in these intervals?
PS. I don't have free cells in these lines, I dont have these lines at all.
lines:
column 1 ... col 195
13:30:20.8 0.78061899
13:30:21.8 5.969546498
13:32:19.8 17.21257881
13:32:20.8 6.922475345
If you don't want to draw a line between two points you must insert an empty line in the data file between the two point entries, so that effectively you have
13:30:20.8 0.78061899
13:30:21.8 5.969546498
13:32:19.8 17.21257881
13:32:20.8 6.922475345
This cannot be done with gnuplot directly, but you can use e.g. awk to do the processing on-the-fly:
set timefmt '%H:%M:%S'
set xdata time
filename = 'data.txt'
plot 'awk ''{split($1,d,":"); t_prev = t; t = (d[1] * 60 + d[2])*60 + d[3]; if (t_prev && (t - t_prev > 10)) print ""; print }'' '.filename with lines
Here, the gap threshold is 10 seconds.
I suppose your miss data identifier is "NaN", then you can use the following command
plot "data" using 1:($2) with linespoints
instead of
plot "data" using 1:2 with linespoints
The former one will ignore the missing data and treat it as blank line and therefore not draw a connecting line across the gap while the latter one will draw continuous, unbroken line.
Just for the records: there are later questions about the same/similar issue.
Avoid connection of points when there is empty data
How to remove line between "jumping" values, in gnuplot?
Removing vertical lines due to sudden jumps in gnuplot
However, my solutions there require transparent color, which was not available in at the time of OP's question (gnuplot 4.6.5, Feb 2014). Nevertheless, there is a solution without external tools like awk or changing the data.
First solution for gnuplot 4.6.: Instead of a transparent line you use a white line which, however, will cover the grid lines, although it will be hardly visible.
Second solution for gnuplot 4.6 is using vectors. This really interrupts the line and will work for gnuplot 5.x as well.
Data:
00:00:00 0.406406
00:00:44 0.339779
00:01:28 0.986602
00:02:13 0.17746
00:02:57 0.0580277
00:03:42 0.586614
00:04:26 0.84247
00:05:11 0.597502
00:05:55 0.0394846
00:06:40 0.369416
00:13:20 0.527109
00:13:42 0.371411
00:14:04 0.851465
00:14:26 0.980312
00:14:48 0.431391
00:15:11 0.545491
00:15:33 0.708445
00:15:55 0.861669
00:16:17 0.277122
00:16:40 0.787273
Script:
### avoid showing a line across larger time gaps
reset
FILE = "SO26510245.dat"
myFmt = "%H:%M:%S"
tGap = 60 # 60 seconds
set format x "%H:%M"
set timefmt "%H:%M:%S"
set xdata time
set ytics 0.5
set key top center noautotitle
set grid x,y
set multiplot layout 3,1
plot FILE u 1:2 w l lc rgb "red" ti "data as is"
myColor(col) = (t0=t1, t1=timecolumn(1), t1-t0>tGap ? 0xffffff : 0x0000ff)
plot t1=NaN FILE u 1:2:(myColor(1)) w l lc rgb var ti "white line"
myGap(col) = (t1-t0>tGap ? NaN : y0)
plot t1=y1=NaN FILE u (t0=t1,t1=timecolumn(1),t0):(y0=y1,y1=$2,myGap(0)):(t1-t0):(y1-y0) \
w vec lc rgb "web-green" nohead ti "with vectors"
unset multiplot
### end of script
Result: (created with gnuplot 4.6.0, from March 2012)

gnuplot "stats" command unexpected min & "out of range" results

I’m trying to develop a histogram script. The plot itself seems correct, but I have some problems or questions:
I don’t understand why the “stats” output says my data file has “out of range” points. What does that mean?
The “stats” minimum value doesn’t look correct, either. From the data file, minimum = -0.0312, but stats reports 0.0.
The script:
# Gnuplot histogram from "Gnuplot In Action", 13.2.1 Jitter plots and histograms (p. 256)
# these functions put data points (x) into bins of specified width
bin(x,width) = width*floor(x/width)
binwidth = 0.01
set boxwidth binwidth
# data file
data_file = "sorted.csv"
png_file = "sorted.png"
datapoint_count = 14
# taking explanations from the data file
set style data linesp
set key autotitle columnheader
set datafile separator "," # CSV format
# histogram
myTitle = "Histogram from \n" . data_file
set title myTitle
set style fill solid 1.0
set xlabel "Slack"
set mxtics
set ylabel "Count"
set yrange [0:*] # min count is always 0
set terminal png # plot file format
set output png_file # plot to file
print "xrange="
show xrange
print "yrange="
show yrange
stats data_file using ($1)
print "STATS_records=", STATS_records
print "STATS_invalid=", STATS_invalid
print "STATS_blank=", STATS_blank
print "STATS_min=", STATS_min
print "STATS_max=", STATS_max
plot data_file using (bin($1,binwidth)):(1) smooth frequency with boxes
The data file:
slack
-0.0312219
-0.000245109
-4.16338e-05
-2.08616e-05
-1.82986e-05
8.31485e-06
1.00136e-05
1.23084e-05
0
0.000102907
0.000123322
0.000138402
0.19044
0.190441
The output:
gnuplot sorted.gp
Could not find/open font when opening font "arial", using internal non-scalable font
xrange=
set xrange [ * : * ] noreverse nowriteback # (currently [-10.0000:10.0000] )
yrange=
set yrange [ 0.00000 : * ] noreverse nowriteback # (currently [:10.0000] )
* FILE:
Records: 9
Out of range: 5
Invalid: 0
Blank: 0
Data Blocks: 1
* COLUMN:
Mean: 0.0424
Std Dev: 0.0792
Sum: 0.3813
Sum Sq.: 0.0725
Minimum: 0.0000 [3]
Maximum: 0.1904 [8]
Quartile: 0.0000
Median: 0.0001
Quartile: 0.0001
STATS_records=9.0
STATS_invalid=0.0
STATS_blank=0.0
STATS_min=0.0
STATS_max=0.190441
If you give a single column to the stats command, the yrange is used to select the range from this column.
At first sight this doesn't make sense, but behaves like a plot command which has only a single column, in which case this single column is the y-value and the row number is choosen as x-value.
So, just move the set yrange part behind the stats command.
data_file = 'sorted.csv'
stats data_file using 1
show variables all
set yrange [0:*]
plot data_file ...

How to specify the start of the x-axis at 1 instead of 0

I use gnuplot to plot execution times measured on the CPU and GPU depending on the data size. So I have two files with the execution times in it. Plotting them is straight forward.
set title "CPU vs GPU"
set xlabel "Number of Particles (* 10'000)"
set ylabel "Time in Microseconds"
plot "cpuTimes.txt" title "CPU" with linespoints, \
"gpuTimes.txt" title "GPU" wit
The resulting plot can be found here: 1
I tried to use xtics however it doesn't shift the x-axis to start at 1 but just starts the ticks at 1. How can I shift the x-axis so it starts at 1 and ends at 50?
Update
Datafile cpuTimes.txt below
64780
129664
195490
266697
327871
391777
459150
517999
582959
647984
717377
790415
830869
900475
959599
1026041
1092899
1156022
1297471
1286325
1349227
1415936
1482857
1539580
1607389
1673436
1737098
1801568
1874431
1935975
2006892
2053077
2129867
2195117
2254467
2314478
2373546
2435416
2506850
2587302
2625556
2674799
2758387
2820720
2896794
2953550
3053817
3089501
3170513
3271537
xtics are only to "label" the x-axis. What you are looking for is some sort of "data manipulation". I'd suggest making use of using like so:
plot "cpuTimes.txt" u ($0+1):1 t "CPU" w lp, \
"gpuTimes.txt" u ($0+1):1 t "GPU" w lp
To make the plot end at 50 there are two ways:
You could specify the x-range with set xrange [1:50] or with
plot [1:50] "cpuTimes.txt" u ($0+1):1 t "CPU" w lp, \
"gpuTimes.txt" u ($0+1):1 t "GPU" w lp
You need to include every like so:
plot "cpuTimes.txt" u ($0+1):1 every 1::::50 t "CPU" w lp, \
"gpuTimes.txt" u ($0+1):1 every 1::::50 t "GPU" w lp
See every for documentation for further reference.
I haven't used gnuplot in awhile, but I believe you can use set xrange to adjust what is plotted.
In your case the command is:
set xrange [ 1 : 50 ]
Give an axis range in your plot command:
plot [1:50] "cpuTimes.txt"

Resources