Thread Subject: datetick and set axis

Subject: datetick and set axis

From: Fiona Buckley

Date: 2 Jan, 2009 10:38:02

Message: 1 of 6

Hi,
I hope someone can help me cause I'm really going mental...

I'm trying to plot a graph using datetick BUT whilst setting the axis so that I have a predefined time span for my ticks.
In the Matlab help file it says I should use xtick BEFORE datetick but even if I do so, it doesn't work. I only seem to be able to get the ticks at the default setting and not as predefined. If I remove the datetick line from my script and only use xtick I get what I want, so my problem can't be caused by the xtick function.
I'm trying to get a 10min spacing and not the 30min default one whilst reading the information on the graph in "time format" and not "matlab format".

Thanks a million for your help

Subject: datetick and set axis

From: Phil Goddard

Date: 3 Jan, 2009 04:07:01

Message: 2 of 6

Have you tried
datetick('x','keepticks')
option?

Phil.

Subject: datetick and set axis

From: Fiona Buckley

Date: 5 Jan, 2009 09:32:01

Message: 3 of 6

"Phil Goddard" <philgoddardNOSPAM@telus.net> wrote in message <gjmo95$82s$1@fred.mathworks.com>...
> Have you tried
> datetick('x','keepticks')
> option?
>
> Phil.

If I do this, I only get the time and no longer the date and the time on my x axis and in addition to this I cannot set the ticks at the desired spacing (in this case 10minutes)

Any other ideas?

Cheers
Fiona

Subject: datetick and set axis

From: Steven Lord

Date: 5 Jan, 2009 14:48:40

Message: 4 of 6


"Fiona Buckley" <buckley_fiona@yahoo.com> wrote in message
news:gjsk2h$h31$1@fred.mathworks.com...
> "Phil Goddard" <philgoddardNOSPAM@telus.net> wrote in message
> <gjmo95$82s$1@fred.mathworks.com>...
>> Have you tried
>> datetick('x','keepticks')
>> option?
>>
>> Phil.
>
> If I do this, I only get the time and no longer the date and the time on
> my x axis and in addition to this I cannot set the ticks at the desired
> spacing (in this case 10minutes)
>
> Any other ideas?

Is this more like what you want?


% Create a vector of datenums -- every ten minutes starting now and ending
tomorrow
x = linspace(now, now+1, 24*6+1);

% Verify that the datenums in x represent ten-minute intervals
datestr(x)

% Create a sample plot
plot(x, (1:length(x)).^2);

% Set the ticks to appear every hour
set(gca, 'XTick', x(1:6:end));

% Call DATETICK with a date format (to display just the hour and minute,
with AM/PM)
% and keep the existing tick locations
datetick('x', 'HH:MM PM', 'keepticks')


The ticks are going to be closely spaced, so you may need to maximize the
figure to see them all. Just adjust the 6 in the next-to-last line to
change the spacing of the ticks if you want.

--
Steve Lord
slord@mathworks.com

Subject: datetick and set axis

From: Fiona Buckley

Date: 6 Jan, 2009 10:46:43

Message: 5 of 6

"Steven Lord" <slord@mathworks.com> wrote in message <gjt6k8$ms2$1@fred.mathworks.com>...
>
> "Fiona Buckley" <buckley_fiona@yahoo.com> wrote in message
> news:gjsk2h$h31$1@fred.mathworks.com...
> > "Phil Goddard" <philgoddardNOSPAM@telus.net> wrote in message
> > <gjmo95$82s$1@fred.mathworks.com>...
> >> Have you tried
> >> datetick('x','keepticks')
> >> option?
> >>
> >> Phil.
> >
> > If I do this, I only get the time and no longer the date and the time on
> > my x axis and in addition to this I cannot set the ticks at the desired
> > spacing (in this case 10minutes)
> >
> > Any other ideas?
>
> Is this more like what you want?
>
>
> % Create a vector of datenums -- every ten minutes starting now and ending
> tomorrow
> x = linspace(now, now+1, 24*6+1);
>
> % Verify that the datenums in x represent ten-minute intervals
> datestr(x)
>
> % Create a sample plot
> plot(x, (1:length(x)).^2);
>
> % Set the ticks to appear every hour
> set(gca, 'XTick', x(1:6:end));
>
> % Call DATETICK with a date format (to display just the hour and minute,
> with AM/PM)
> % and keep the existing tick locations
> datetick('x', 'HH:MM PM', 'keepticks')
>
>
> The ticks are going to be closely spaced, so you may need to maximize the
> figure to see them all. Just adjust the 6 in the next-to-last line to
> change the spacing of the ticks if you want.
>
> --
> Steve Lord
> slord@mathworks.com
>






Hi again,
sorry but this is not really what I'm looking for...
I have data that is collected every minute over a time period of several months. To facilitate things, I converted my 2 "date & time columns" in a single one using datenum (My x axis - time - is therefore in Matlab datenum format). I broke down the data and am plotting a graph every four hours.
What I want to do is :
1- On the graph have the x data labelling back in "real time" (date and HH:MM:SS). For that I need to use datetick
2- Set the ticks on the x axis to be every 10minutes in order to see progression over time and have a 10 minute grid on the graph. For this I need set axis.
However, I can't seem to be able to use BOTH functions in my script. If I use both, only one (datetick) has impact on my graph (and this no matter the order) but if I only encode either of the two, whichever one it is has an impact on the graph.

I hope this makes things clearer and that someone can help me.
Fiona

Subject: datetick and set axis

From: Steven Lord

Date: 6 Jan, 2009 14:41:27

Message: 6 of 6


"Fiona Buckley" <buckley_fiona@yahoo.com> wrote in message
news:gjvcqj$73t$1@fred.mathworks.com...
> "Steven Lord" <slord@mathworks.com> wrote in message
> <gjt6k8$ms2$1@fred.mathworks.com>...
>>
>> "Fiona Buckley" <buckley_fiona@yahoo.com> wrote in message
>> news:gjsk2h$h31$1@fred.mathworks.com...
>> > "Phil Goddard" <philgoddardNOSPAM@telus.net> wrote in message
>> > <gjmo95$82s$1@fred.mathworks.com>...
>> >> Have you tried
>> >> datetick('x','keepticks')
>> >> option?
>> >>
>> >> Phil.
>> >
>> > If I do this, I only get the time and no longer the date and the time
>> > on
>> > my x axis and in addition to this I cannot set the ticks at the desired
>> > spacing (in this case 10minutes)
>> >
>> > Any other ideas?
>>
>> Is this more like what you want?
>>
>>
>> % Create a vector of datenums -- every ten minutes starting now and
>> ending
>> tomorrow
>> x = linspace(now, now+1, 24*6+1);
>>
>> % Verify that the datenums in x represent ten-minute intervals
>> datestr(x)
>>
>> % Create a sample plot
>> plot(x, (1:length(x)).^2);
>>
>> % Set the ticks to appear every hour
>> set(gca, 'XTick', x(1:6:end));
>>
>> % Call DATETICK with a date format (to display just the hour and minute,
>> with AM/PM)
>> % and keep the existing tick locations
>> datetick('x', 'HH:MM PM', 'keepticks')
>>
>>
>> The ticks are going to be closely spaced, so you may need to maximize the
>> figure to see them all. Just adjust the 6 in the next-to-last line to
>> change the spacing of the ticks if you want.
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>>
>
> Hi again,
> sorry but this is not really what I'm looking for...
> I have data that is collected every minute over a time period of several
> months. To facilitate things, I converted my 2 "date & time columns" in a
> single one using datenum (My x axis - time - is therefore in Matlab
> datenum format). I broke down the data and am plotting a graph every four
> hours.
> What I want to do is :
> 1- On the graph have the x data labelling back in "real time" (date and
> HH:MM:SS). For that I need to use datetick
> 2- Set the ticks on the x axis to be every 10minutes in order to see
> progression over time and have a 10 minute grid on the graph. For this I
> need set axis.
> However, I can't seem to be able to use BOTH functions in my script. If I
> use both, only one (datetick) has impact on my graph (and this no matter
> the order) but if I only encode either of the two, whichever one it is has
> an impact on the graph.

What you've described is pretty much _exactly_ what I did above, modulo the
fact that I only used 'HH:MM PM' as the date format (and assuming you add
"grid on" after the DATETICK call.) The next-to-last line of code sets the
ticks to be every ten minutes (your requirement 2) and the last line of code
sets the tick labels to be date strings (your requirement 1). The
'keepticks' parameter in the DATETICK call forces DATETICK to use the ticks
that I set on the next-to-last line and to just change the tick labels.

Can you clarify what additional requirements you have that this code does
not satisfy?

--
Steve Lord
slord@mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
datetick Shanmugam Kannappan 5 Jan, 2009 04:39:48
keepticks Phil Goddard 2 Jan, 2009 23:10:05
datetick Phil Goddard 2 Jan, 2009 23:10:05
rssFeed for this Thread

Contact us at files@mathworks.com