change scales from the x axis

Hi,
I intend to do a chart with two yaxis, the code is the following:
dates=datenum(dataSet(:,1));
%SPX
SPX=dataSet(:,2);
%VIX
VIX=dataSet(:,3);
plotyy(dates,SPX,dates,VIX);
%datevc divides the date in different columns, first colum is the year,
%second the month and thrid the day
d=datevec(dates);
%Takes just the year (first column)
d=d(:,1);
%takes every year just once
[a,idx]=unique(d(:,1),'first');
ylabel('VIX');
set(gca,'xtick',dates(idx),'xticklabel',a)
ytix = get(gca,'YTick');
set(gca,'YTick',ytix(2:end));
This is working but unfortunately besides the years I have also the numeric date displayed on the x axis, how can I change that?
is there a way to make both y axis black instead of blue and green?

 Accepted Answer

use
[ax,h1,h2]=plotyy(dates,SPX,dates,VIX);
set(ax(1),'ycolor','k')
set(ax(2),'ycolor','k')

11 Comments

thanks, this has solved the color issue, do you have a solution to see only the dates on the xaxis and not the numerical value?
use
set(ax,'xtick',dates(idx),'xticklabel',a)
Locks
Locks on 2 May 2013
Edited: Locks on 2 May 2013
that works as well, thanks
the last thing that is missing now is that both time series start at the left and right yaxis (so that there are no spaces between the y axis and the time series)
is there something similar to this:
axis([xmin xmax ymin ymax]) when there are two y axis?
set(ax(1),'ylim',[min(y1) max(y1)]) %y1 your first signal
set(ax(2),'ylim',[min(y2) max(y2)]) %y2 your second signal
that's working perfectly. I tried in addition to get a value for every step of 200 using this:
set(ax(1),'ylim',[0:200:2000]) set(ax(2),'ylim',[0:20:100])
but that does not work, is there something else I can do?
In addition, there is still a space between the y axis and the times series, I tried this:
axis tight
but that does only work for one of the series and the left y axis, but not for both
It should be
set(ax(1),'ylim',[0 2000])
set(ax(2),'ylim',[0 100])
yes, this is fine but this one only values displayed on the left yaxis are 0 1000 and 2000 and I would like to have a scale in steps of 200
the same goes for the right y axis
do you have a solution for the second problem as well?
set(ax(1),'ytick',[0:200:2000])
set(ax(2),'ytick',[0:20:100])
perfect, thanks!!
Have you also a solution that there are no spaces between the plot and the y axis, in other words the plot should start at the left yaxis and ends at the richt yaxis
set(ax,'xlim',[min(x) max(x)])
perfect, thanks

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!