From: Paul on 14 Feb 2010 16:22 Hi, Hopefully someone can help me here because i'm lost for fixing this. I'm trying to plot two time series at shared x-values but with different scales on the y-axis. I extract both time series from a financial time series object since plotyy doesn't like this construct. My problem is that I can't get the dates on the x-axis to appear properly. I simply want to print a series of common dates and then set the Xlim. plot_dates = X0_TS.dates('01-Jul-1980::01-Jan-2008'); hprx_plot = hprx_zeros_TS('29-Jun-1980::31-Dec-2007'); X0_plot = X0_TS('01-Jul-1980::01-Jan-2008'); X = [plot_dates fts2mat(hprx_plot.MAT5) fts2mat(X0_plot.RGDP)]; [ax,h1,h2] = plotyy(datenum(X(:,1)),X(:,2),datenum(X(:,1)),X(:,3)); title('Excess Holding Period Returns (5 Year Matury Zero) plotted alongside uncertainty on Real GDP') grid on xlabel('Date','Color','k'); set(ax,'YColor','k','Box','on'); set(h1,'color','r') set(h2,'color','b') set(get(ax(1),'Ylabel'),'String','HPRX', 'color','r') set(get(ax(2),'Ylabel'),'String','DiB', 'color','b') datetick('x',10,'keepticks') Many thanks is advance
From: dpb on 14 Feb 2010 17:32 Paul wrote: > Hi, > Hopefully someone can help me here because i'm lost for fixing this. I'm > trying to plot two time series at shared x-values but with different > scales on the y-axis. ... > My problem is that I can't get the dates on the x-axis to appear > properly. I simply want to print a series of common dates and then set > the Xlim. .... doc datetick granted, it's not easy to find in documentation unless you know it exists...at least my version doesn't mention it anywhere in the Graphics section. (TMW, anybody check on this in current...???) --
From: Paul on 14 Feb 2010 18:00 Thanks for the reply. This is my latest attempt. The series are plotted with common dates and the limits work for the x-axis. However, if I try and specify the Xticks or use datetick is goes all screwy? [ax,h1,h2] = plotyy(datenum(X(:,1)),X(:,2),datenum(X(:,1)),X(:,3)); title('Excess Holding Period Returns (5 Year Matury Zero) plotted alongside uncertainty on Real GDP') grid on grid minor xlabel('Date','Color','k'); set(ax,'YColor','k','Box','on'); set(h1,'color','r','LineWidth',1.0) set(h2,'color','b','LineWidth',1.0) set(get(ax(1),'Ylabel'),'String','HPRX', 'color','r') set(ax(1),'XLim',[datenum(1980, 07, 01) datenum(2009, 07, 01)]) set(ax(1),'YLim',[-0.2 +0.2]) set(get(ax(2),'Ylabel'),'String','DiB', 'color','b') set(ax(2),'XLim',[datenum(1980, 07, 01) datenum(2009, 07, 01)]) set(ax(2),'YLim',[0 1.0])
From: Paul Mennen on 15 Feb 2010 15:28 "Paul " <paulsastud(a)hotmaill.com> wrote > My problem is that I can't get the dates on the x-axis to appear properly. I think I've gotten date ticks to do similar to what you want, although I remember it wasn't straightforward. Can't really remember what I did since I've now gravitated to a different approach i.e. plotting the time (seconds, months, years, whatever) past a specified starting point. Although DateTicks are often preferable for a chart to be published, for data exploration and cursoring, my approach is easier. That's the approach I use with plt.m, which I offer on the file exchange as an easier to use version of plotyy (or plot for that matter). To see what I mean, try the example demo\pltn.m and not that when you click on the graph the cursor readout shows both the time since the start as well as the date and time of the point. The other examples in that folder show off many other features of plt.m. I haven't heard comments like the title of this thread in reference to my alternative so I hope you give it a try. And certainly if you have any questions, comments, opinions, or suggestions about plt.m I'm always interested in hearing from the users of plt. Paul
From: dpb on 15 Feb 2010 16:15 Paul wrote: > Thanks for the reply. > This is my latest attempt. The series are plotted with common dates and > the limits work for the x-axis. However, if I try and specify the Xticks > or use datetick is goes all screwy? .... I'd forgotten this as don't use dateticks much if at all but in my older version R12, it seems as though plotyy isn't smart enough to know to turn off one set of x axes ticks or to convert both so you end up w/ one set of normal and another w/ date strings which indeed does look funky. The following seems to work here... ax = plotyy(t,x,t,y); % turn off 2nd axes tick marks set(ax(2),'XTick',[]) set(ax(2),'XTickLabel',[]) datetick('x',23,'keepticks') Note axis(ax(2),'off') might seem more friendly except it also makes the 2nd y-axis ticks invisible which may not be what is wanted. Depending on the number of ticks marks and format, may need to adjust particularly font size to keep from the strings running into each other. This is a general "feature" of most of handle graphics I've noted... :( --
|
Next
|
Last
Pages: 1 2 3 4 Prev: Applying a function to a matrix Next: differentiating a piecewise function |