I have two financial graphics and I need to analyze how them perform comparing to each other. I wrote such program:
clear
fLog = fopen('log.log');
data = textscan(fLog, '%f:%f:%f:%f %f %f %f');
fclose(fLog);
% hh:min:sec:millisec
secvec = [60*60 60 1 1e-3];
x = [data{1:4}] * secvec';
y = data{5};
yPrice = data{6};
xindays = x / (24*60*60);
plot(xindays, y);
hold on
plot(xindays, yPrice);
ticklabelformat(gca,'y','%g')
ticklabelformat(gca,'x',{@tick2datestr,'x','HH:MM:SS'})
log.log file example
The problem is that as two graphics has completely different “Y” value them both looks like “straight” line. So I need somehow to have two Y axis, probably one on the left and one on the right, but they should has the same scale, meaning 1% change should be the same on both graphics so I should be able to compare which stock outperforms and where. If it is possible to do that and how?
I also want to draw this graphics using different colors but I likely can google myself how to do that once above problem is resolved.
You’re looking for plotyy. Because you also change the xticks, I advise to remove the xticks from one of the two resulting axes, otherwise they’ll overlap:
This gives you the following figure:
EDIT:
As you can see, plotyy just makes sure that all data is in the visible window. So the y-axis scalings are not equal. If you really want that, you can always change that after using plotyy. eg:
The ideal visible ranges depend on the range of the data itself, so you’ll have to fix this yourself.