简体   繁体   中英

Plot date on x-axis in Octave

I'm trying to make a plot with nicely formatted datetimes on the x-axis in Octave, but can't get it to work.

The data I have looks like this (= default datetime format 31 'yyyy-mm-dd HH:MM:SS' )

2015-05-29 20:30:23, 100, 10
2015-05-29 21:00:23, 94, 25
2015-05-29 21:30:23, 92, 30

or as seconds since starting epoch (1970-1-1)

1432917023, 100, 10
1432918823, 94, 25
1432920623, 92, 30

I want to plot the 2nd and 3rd column of the dataset with the datetimes of the first column on the x-axis. I've googled around and couldn't find a clear answer for this seemingly easy problem :(

I have tried using datetick (after reading this link ). I also tried to fiddle with strptime but both to no avail.

Thanks for the help!

logs = [1432917023,100, 10;
        1432918823, 94, 25;
        1432920623, 92, 30];

# time_t / (24*60*60) = datenum() -719529.375
# convert datenum() from time_t
logs(:,1) = logs(:,1) / (24*60*60) + 719529.375;

plot (logs(:,1), logs(:,2))
plot (logs(:,1), logs(:,3))

datetick('x', "%H:%M");

The following code first plots the two datasets against their dates:

dates = [datetime('2015-05-29 20:30:23'),
         datetime('2015-05-29 21:00:23'),
         datetime('2015-05-29 21:30:23')];
data = [100, 10;
        94, 25;
        92, 30];
hold on;
plot(dates, data(:,1), 'rd-');
plot(dates, data(:,2), 'bo-');
hold off;

数小时绘图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM