user1669504
user1669504

Reputation: 11

How to plot dates read from a csv file on the x axis

I've been having a bit of a struggle plotting Temperature vs Dates in Octave. I am reading the dates from a csv file, I am doing this:

TempData=csv2cell(filename.csv,1) %File with dates and temperatures

Date=TempData(:,2) %Second column has the dates in YYYY-MM-DD HH:MM:SS

datev=datevec(Date:31) % which gives me an output by columns 

date2=datenum(datev) 

Then I plot:

plot(date2,MeanT)

And I get this output:

The image is what I want, but the x axis should state the dates in their YYYY-MM-DD HH:MM:SS format

Upvotes: 0

Views: 245

Answers (2)

Piero
Piero

Reputation: 686

You have to use datetick

datetick('x','yyyy-mm-dd')

Upvotes: 0

Tasos Papastylianou
Tasos Papastylianou

Reputation: 22245

Have a look at datetick (i.e. type help datetick in an octave terminal).

E.g.

datetick( 'x', 'yyyy-mm-dd' )

will convert your x-axis which consists of datenum values into string ticklabels in 'yyyy-mm-dd' format (e.g. '2021-08-20').

If you require a different format, have a look at help datestr.

Upvotes: 1

Related Questions