The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

Posts: 9,850
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 =
>> 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]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.