Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: put date in x axis when using plotyy
Replies: 26   Last Post: Jul 14, 2014 9:50 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,250
Registered: 6/7/07
Re: put date in x axis when using plotyy
Posted: Jul 13, 2014 2:42 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 07/13/2014 12:19 PM, joanna wrote:
...

>> --It doesn't work with fliplr either..
> I get the same error:
> ??? Error using ==> set
> Values must be monotonically increasing.
>
> Error in ==> trial at 15
> set(yaxes(1),'xtick',dn)


OK, I overlooked that there were some repeated dates in your pasted
example--was hard to see w/ the line wrap...

OK, this works here as advertised, albeit as suspected owing to the
length of the labels its pretty crowded.

>> dn=datenum(fliplr(data(:,3:5)));
>> datestr(dn)

ans =
02-Jun-1966
03-Jun-1966
04-Jun-1966
04-Jun-1966
05-Jun-1966
06-Jun-1966
08-Jun-1966
08-Jun-1966
08-Jun-1966
11-Jun-1966
>> hAx=plotyy(dn,data(:,2),dn,data(:,9),@plot,@stem);
>> set(hAx,'xticklab',[])
>> datetick(hAx(1),'x','yyyy-mm-dd','keepticks')


That's run together until

>> set(hAx(1),'fontsize',8)

and stretch the size of the x-axis some.

>> datetick(hAx(1),'x','yy-mm-dd','keepticks')

This is somewhat more legible.

You'll have to experiment with how many and where it places the tick
marks with your full data set. As noted, you may want to do something
with generating only a half-dozen or so.

There are many "variations on a theme" available here--one of the
simplest is something on the order of--

>> dt=linspace(dn(1),dn(end),6);
>> set(hAx,'xtick',dt)
>>


Alternatively, you can also set the xlim values to datenums
corresponding to the beginning of a month and/or year and as suggested
previously use the vectorizing capability to increment by 6 months or
some other suitable interval so that the ticks line up with specific
"neat" calendar intervals.

Again, the key is to decide what you do want and then work to achieve
that result. The tools/methods to manipulate the dates and display them
are all demonstrated here.

This again presumes that you plot the data against the actual date
values. If it is mandatory to use the sequential serial number instead
so that the multiple data values show up as separate locations on the
x-axis, then you've got to generate a different problem as you'll be
asking to plot the location at something different than the actual date.
There are some ways I can think of to handle that, but they would take
additional fiddling to make something useful of the x-axis.
My first inclination would be to separate the repeated values into
alternate datasets and plot them as other data points color-coded
perhaps as the second, third, etc., repeat for the day but still use the
actual date on the axis.

Otherwise, you'll be forced to generate some labels at points from the
actual date and set them appropriately but the indication to the user
will always be somewhat misleading; the more so the more repeats there
are so the accumulated distance of zero actual time versus displayed
axis time becomes larger.

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.