Thread Subject: Axes ticks irregular spacing

Subject: Axes ticks irregular spacing

From: dage Tarari

Date: 29 Jun, 2009 11:53:01

Message: 1 of 9

Hi all,

I wonder if it is possible to create X axis ticks with non-monotonically increasing values. Example: if the x-axis represents time and we want to locate one tick for the first day of every month, the spacing will be 28 and 31 between 01 Feb, 01 Mar and 01 Apr, respectively.

Thanks!!
Belen

Subject: Axes ticks irregular spacing

From: Rune Allnor

Date: 29 Jun, 2009 11:56:39

Message: 2 of 9

On 29 Jun, 13:53, "dage Tarari" <ahs...@hjg.es> wrote:
> Hi all,
>
> I wonder if it is possible to create X axis ticks with non-monotonically increasing values.

Of course it is. Try:

set(gca,'xtick',(0:0.2:1).^2)

Rune

Subject: Axes ticks irregular spacing

From: us

Date: 29 Jun, 2009 11:59:03

Message: 3 of 9

"dage Tarari" <ahsghd@hjg.es> wrote in message <h2a9ut$dmc$1@fred.mathworks.com>...
> Hi all,
>
> I wonder if it is possible to create X axis ticks with non-monotonically increasing values. Example: if the x-axis represents time and we want to locate one tick for the first day of every month, the spacing will be 28 and 31 between 01 Feb, 01 Mar and 01 Apr, respectively.
>
> Thanks!!
> Belen

one of the solutions is outlined below

     plot(1:10);
     set(gca,...
          'xtick',[1,2,pi,2*pi,9],...
          'xticklabel',{'1','2','pi','2pi','9Hz'});

us

Subject: Axes ticks irregular spacing

From: Belen

Date: 29 Jun, 2009 12:02:01

Message: 4 of 9

Thank you so much Rune,
Belen

Rune Allnor <allnor@tele.ntnu.no> wrote in message <4c72e071-b1c2-49f6-8a7b-cea8dff43651@y7g2000yqa.googlegroups.com>...
> On 29 Jun, 13:53, "dage Tarari" <ahs...@hjg.es> wrote:
> > Hi all,
> >
> > I wonder if it is possible to create X axis ticks with non-monotonically increasing values.
>
> Of course it is. Try:
>
> set(gca,'xtick',(0:0.2:1).^2)
>
> Rune

Subject: Axes ticks irregular spacing

From: Belen

Date: 29 Jun, 2009 12:14:02

Message: 5 of 9

Excuse me Rune but I still haven't found the way to do the following:
set(gca,'xtick',[0 31 59 90 120 151 181 212 243 273 304 334 365])
0, 31, 28, etc. are julian days.
I'll be very grateful for any advice,
Belen









Rune Allnor <allnor@tele.ntnu.no> wrote in message <4c72e071-b1c2-49f6-8a7b-cea8dff43651@y7g2000yqa.googlegroups.com>...
> On 29 Jun, 13:53, "dage Tarari" <ahs...@hjg.es> wrote:
> > Hi all,
> >
> > I wonder if it is possible to create X axis ticks with non-monotonically increasing values.
>
> Of course it is. Try:
>
> set(gca,'xtick',(0:0.2:1).^2)
>
> Rune

Subject: Axes ticks irregular spacing

From: us

Date: 29 Jun, 2009 12:25:03

Message: 6 of 9

"Belen " <ahsghd@hjg.es> wrote in message <h2ab6a$frb$1@fred.mathworks.com>...
> Excuse me Rune but I still haven't found the way to do the following:
> set(gca,'xtick',[0 31 59 90 120 151 181 212 243 273 304 334 365])
> 0, 31, 28, etc. are julian days.
> I'll be very grateful for any advice,
> Belen

what's wrong with this perfect syntax?
naturally, you have to PLOT/LINE/etc first - or - set the axis's xlim...
otherwise, it does not show up...

     plot(1:370);
     set(gca,'xtick',[0 31 59 90 120 151 181 212 243 273 304 334 365]);

us

Subject: Axes ticks irregular spacing

From: Steven Lord

Date: 29 Jun, 2009 13:13:46

Message: 7 of 9


"dage Tarari" <ahsghd@hjg.es> wrote in message
news:h2a9ut$dmc$1@fred.mathworks.com...
> Hi all,
>
> I wonder if it is possible to create X axis ticks with non-monotonically
> increasing values. Example: if the x-axis represents time and we want to
> locate one tick for the first day of every month, the spacing will be 28
> and 31 between 01 Feb, 01 Mar and 01 Apr, respectively.

Others have suggested setting the XTick and/or XTickLabel properties, but
from your description I think you may prefer using the DATETICK function in
addition.

x = datenum(2009, 1:12, 1);
y = (1:length(x)).^2;
plot(x, y);
set(gca, 'XTick', x)
datetick('x', 6)

% alternately, if you want all the first days labeled, replace the last line
above with:
datetick('x', 6, 'keepticks')

--
Steve Lord
slord@mathworks.com

Subject: Axes ticks irregular spacing

From: Belen

Date: 29 Jun, 2009 13:19:01

Message: 8 of 9

Thank you very much US!!
Belen


"us " <us@neurol.unizh.ch> wrote in message <h2abqv$9v$1@fred.mathworks.com>...
> "Belen " <ahsghd@hjg.es> wrote in message <h2ab6a$frb$1@fred.mathworks.com>...
> > Excuse me Rune but I still haven't found the way to do the following:
> > set(gca,'xtick',[0 31 59 90 120 151 181 212 243 273 304 334 365])
> > 0, 31, 28, etc. are julian days.
> > I'll be very grateful for any advice,
> > Belen
>
> what's wrong with this perfect syntax?
> naturally, you have to PLOT/LINE/etc first - or - set the axis's xlim...
> otherwise, it does not show up...
>
> plot(1:370);
> set(gca,'xtick',[0 31 59 90 120 151 181 212 243 273 304 334 365]);
>
> us

Subject: Axes ticks irregular spacing

From: Belen

Date: 29 Jun, 2009 13:23:01

Message: 9 of 9

Thank you very much Steven. We are all used to program here in my office, but my none of us knew how to do this simple irregular spacing.
Best whishes,
Belen


"Steven Lord" <slord@mathworks.com> wrote in message <h2aeku$pld$1@fred.mathworks.com>...
>
> "dage Tarari" <ahsghd@hjg.es> wrote in message
> news:h2a9ut$dmc$1@fred.mathworks.com...
> > Hi all,
> >
> > I wonder if it is possible to create X axis ticks with non-monotonically
> > increasing values. Example: if the x-axis represents time and we want to
> > locate one tick for the first day of every month, the spacing will be 28
> > and 31 between 01 Feb, 01 Mar and 01 Apr, respectively.
>
> Others have suggested setting the XTick and/or XTickLabel properties, but
> from your description I think you may prefer using the DATETICK function in
> addition.
>
> x = datenum(2009, 1:12, 1);
> y = (1:length(x)).^2;
> plot(x, y);
> set(gca, 'XTick', x)
> datetick('x', 6)
>
> % alternately, if you want all the first days labeled, replace the last line
> above with:
> datetick('x', 6, 'keepticks')
>
> --
> 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
code us 29 Jun, 2009 08:04:03
plot us 29 Jun, 2009 08:04:03
graphics handle us 29 Jun, 2009 08:04:03
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com