Thread Subject:
problem with Xtick

Subject: problem with Xtick

From: Robbie Brady

Date: 18 Aug, 2012 11:18:09

Message: 1 of 4

I am having issues displaying specified xtick labels using 'XTick.'

My code looks as follows:
figure (3)
hold on
plot (radardate, Pwave_radar);
plot (radardate, mean_Pwave_radar,'r')
hold off
legend ('Wave Power', 'Mean Wave Power')
title ('WERA HF Radar Derived Wave Power Cell 3592')
ylabel ('Power (W/m^2)')
datetick('x')
set(gca,'XTick',xdata)

where xdata is an array created by the command:

xdata = [734947;734954;734961;734968;734975;734982;734989;734996];

The corresponding string dates are 19/03/2012, 26/03/2012, 02/04/2012 etc etc...

However, when plotted, matlab returns dateticks for the 1st of each month, march-june... 03/01, 04/01 etc etc...

Any ideas? This is giving me a headache...

Many thanks

Subject: problem with Xtick

From: Bruno Luong

Date: 18 Aug, 2012 12:53:06

Message: 2 of 4

xdata = [734947;734954;734961;734968;734975;734982;734989;734996];
plot(xdata,rand(size(xdata)));
set(gca,'xtick',xdata,'xlim',xdata([1 end]));
datetick('x','keeplimits','keepticks');

% Bruno

Subject: problem with Xtick

From: Steven_Lord

Date: 20 Aug, 2012 13:31:12

Message: 3 of 4



"Robbie Brady" <robbie.brady@postgrad.plymouth.ac.uk> wrote in message
news:k0ntlh$k1a$1@newscl01ah.mathworks.com...
> I am having issues displaying specified xtick labels using 'XTick.'
>
> My code looks as follows:
> figure (3)
> hold on
> plot (radardate, Pwave_radar);
> plot (radardate, mean_Pwave_radar,'r')
> hold off
> legend ('Wave Power', 'Mean Wave Power')
> title ('WERA HF Radar Derived Wave Power Cell 3592')
> ylabel ('Power (W/m^2)')
> datetick('x')
> set(gca,'XTick',xdata)
>
> where xdata is an array created by the command:
>
> xdata = [734947;734954;734961;734968;734975;734982;734989;734996];
> The corresponding string dates are 19/03/2012, 26/03/2012, 02/04/2012 etc
> etc...
>
> However, when plotted, matlab returns dateticks for the 1st of each month,
> march-june... 03/01, 04/01 etc etc...
>
> Any ideas? This is giving me a headache...

You didn't tell DATETICK to keep the exact tick locations you specified, so
it chose ones that "looked nice." As Bruno posted, use the 'keepticks' and
'keeplimits' options with DATETICK; see the documentation for that function
for more information on those options.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: problem with Xtick

From: Robbie Brady

Date: 23 Aug, 2012 19:51:07

Message: 4 of 4

"Steven_Lord" <slord@mathworks.com> wrote in message <k0te6v$ed8$1@newscl01ah.mathworks.com>...
>
>
> "Robbie Brady" <robbie.brady@postgrad.plymouth.ac.uk> wrote in message
> news:k0ntlh$k1a$1@newscl01ah.mathworks.com...
> > I am having issues displaying specified xtick labels using 'XTick.'
> >
> > My code looks as follows:
> > figure (3)
> > hold on
> > plot (radardate, Pwave_radar);
> > plot (radardate, mean_Pwave_radar,'r')
> > hold off
> > legend ('Wave Power', 'Mean Wave Power')
> > title ('WERA HF Radar Derived Wave Power Cell 3592')
> > ylabel ('Power (W/m^2)')
> > datetick('x')
> > set(gca,'XTick',xdata)
> >
> > where xdata is an array created by the command:
> >
> > xdata = [734947;734954;734961;734968;734975;734982;734989;734996];
> > The corresponding string dates are 19/03/2012, 26/03/2012, 02/04/2012 etc
> > etc...
> >
> > However, when plotted, matlab returns dateticks for the 1st of each month,
> > march-june... 03/01, 04/01 etc etc...
> >
> > Any ideas? This is giving me a headache...
>
> You didn't tell DATETICK to keep the exact tick locations you specified, so
> it chose ones that "looked nice." As Bruno posted, use the 'keepticks' and
> 'keeplimits' options with DATETICK; see the documentation for that function
> for more information on those options.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Thanks guys, I wasn't aware of the 'keepticks' function before, but the code works perfectly now.

Cheers

Tags for this Thread

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.

rssFeed for this Thread

Contact us