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?

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 2 de Mayo de 2013

0 votos

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

11 comentarios

Locks
Locks el 2 de Mayo de 2013
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 el 2 de Mayo de 2013
Editada: Locks el 2 de Mayo de 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
Locks
Locks el 2 de Mayo de 2013
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])
Locks
Locks el 2 de Mayo de 2013
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])
Locks
Locks el 2 de Mayo de 2013
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)])
Locks
Locks el 2 de Mayo de 2013
perfect, thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by