Using dateaxis to format x-axis

View: New views
5 Messages — Rating Filter:   Alert me  

Using dateaxis to format x-axis

by rmcd :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I must be misunderstanding the use of Dateaxis (in the financial package). I'm using 3.0.2, Cygwin.

I run this:

x=732000:732010;
plot(x,x);
dateaxis("x"); % I get the same result with and without "x".
ticks=get(gca(), "xtick") % this is a diagnostic, returning [](0x0)

The plot is unchanged by the dateaxis command and I get these errors:

error: invalid matrix index = 1
error: evaluating binary operator `-' near line 94, column 17
error: evaluating binary operator `+' near line 94, column 28
error: evaluating assignment expression near line 94, column 9
error: called from `dateaxis' in file `/usr/share/octave/packages/
financial-0.2.2/dateaxis.m'

Ticks has a value of [](0x0), which I gather is due to the auto-mode tick assignment. I think the call to "ticks(1)" generates the first error.

Thanks very much for any help.

Bob

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: Using dateaxis to format x-axis

by dbateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


rmcd wrote:
I must be misunderstanding the use of Dateaxis (in the financial package).
I'm using 3.0.2, Cygwin.
No you misunderstood nothing. In Octave 3.0.x the tick position are calculated when they are drawn. Therefore the get(gca(),'xtick') command return [] which of course has no zero index. This might be fixed in dateaxis with

x = get (gca(), strcat (ax, "tick);
if (isempty (x))
  # Must be 3.0.x. Force drawnow to get the ticks right
  drawnow ();
   x = get (gca(), strcat (ax, "tick);
endif

the workaround for you is

x=732000:732010;
plot(x,x);
drawnow();
dateaxis("x"); % I get the same result with and without "x".
ticks=get(gca(), "xtick") % this is a diagnostic, returning [](0x0)

D.

Re: Using dateaxis to format x-axis

by rmcd :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

dbateman wrote:
the workaround for you is

x=732000:732010;
plot(x,x);
drawnow();
dateaxis("x"); % I get the same result with and without "x".
ticks=get(gca(), "xtick") % this is a diagnostic, returning [](0x0)
Thank you for the response and explanation. However, when I call get(gca(),"xtick") after drawnow I still get []. And I still get the same error when calling dateaxis:

octave:15> x=732000:732010;
octave:16> plot(x,x);
octave:17> drawnow();
octave:18> dateaxis("x");
error: invalid matrix index = 1
error: evaluating binary operator `-' near line 94, column 17
error: evaluating binary operator `+' near line 94, column 28
error: evaluating assignment expression near line 94, column 9
error: called from `dateaxis' in file `/usr/share/octave/packages/financial-0.3.0/dateaxis.

Re: Using dateaxis to format x-axis

by dbateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorry, right explanation. Wrong problem :-)

The explanation I gave applies to [xyzca]lim but not [xyz]tick properties. In fact in Octave 3.0.x, when [xyz]tickmode is set to "auto", Octave leaves gnuplot to calculate the tick positions, and so Octave has no idea of where the ticks are. It seems dateaxis works fine with 3.1.x, but the only way to get it to work with 3.0.x is to manually set the tick position, with something like

x=732000:732010;
plot(x,x);
set (gca(),'xtick',732000:2:732010)
dateaxis("x"); % I get the same result with and without "x".
ticks=get(gca(), "xtick") % this is a diagnostic, returning [](0x0)


D.

Re: Using dateaxis to format x-axis

by rmcd :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

a
dbateman wrote:
x=732000:732010;
plot(x,x);
set (gca(),'xtick',732000:2:732010)
dateaxis("x"); % I get the same result with and without "x".
ticks=get(gca(), "xtick") % this is a diagnostic, returning [](0x0)
I still can't get dateaxis("x") to work in this example, but what does work (from a different thread) is to add this to your example (basically, do everything manually):

datalabels={'a','b','c','d','e'};
set(gca(),'xticklabel',datalabels);

Thanks very much. I'll grab 3.1.50 and take a look.
LightInTheBox - Buy quality products at wholesale price!