1

I am trying to plot a graph by datetime value.

Consider this example CSV (streetnoise.csv):

datetime,noise level
2018-12-03 03:31:12.592,10
2018-12-03 03:31:15.832,10
2018-12-03 03:31:17.062,11
2018-12-03 03:31:19.292,12
2018-12-03 03:31:23.532,11
2018-12-03 03:31:25.762,10
2018-12-03 03:31:26.002,23
2018-12-03 03:31:28.242,10
2018-12-03 03:31:34.492,10
2018-12-03 03:31:34.722,9

So this just stores street noise measurements as tuples. I want to draw a plot from that, using Octave:

# Load the data
pkg load io
csv_data = csv2cell("streetnoise.csv")

# Parse the datetimes
datevalues = datenum(csv_data(2:end,1), "yyyy-mm-dd HH:MM:SS.FFF")
seconds = (datevalues - datevalues(1)) * 24 * 60 * 60

# Get noise levels
noiseLevels = [csv_data{2:end,2}]

# Plot by seconds since start
h = figure(1)
plot(seconds, noiseLevels)
title("Levels per seconds")
xlim([min(seconds) max(seconds)])

# Plot by datenum
i = figure(2)
plot(datevalues, noiseLevels)
title("Levels per datevalues")

The content of the first figure is readable:

Working

However, it is not really understandable, since the reader has to know when measurements started an to calculate the time.

The second figure is just empty:

Not working

How can I plot with the datenum values? I wanted to try datenum parsing for labelling afterwards, but I didn't even come that far.

When I add xlim([min(datevalues) max(datevalues)]), I only get to see the y axis.

Bowi
  • 1,378
  • 19
  • 33
  • As matzeri explained this is a known problem with OpenGL toolkits due to float (single) precision data types. There is another workaround beside using gnuplot: Substract 1.January 2018 from your date so that the remaining dates fit into singles – Andy Dec 18 '18 at 06:06
  • 1
    have a look at my answer here addressing the same problem: https://stackoverflow.com/a/53242735/4183191 – Tasos Papastylianou Dec 18 '18 at 09:16

1 Answers1

2

The graph works with

graphics_toolkit("gnuplot")

the default "fltk" graph toolkit uses numbers as "single", and it has not enough digit to discriminate the difference in seconds between dates. Gnuplot uses "double" and it can discriminate

enter image description here

matzeri
  • 8,062
  • 2
  • 15
  • 16
  • I'm sad to say but fltk isn't the default toolkit since Octave 4.0 where Qt was choosen AS default. But Im still using the cli and fltk – Andy Dec 18 '18 at 06:09
  • @Andy always cli and gnuplot here. Fltk has too many issue on my system – matzeri Dec 18 '18 at 07:38