How can I make the dateticks update when I zoom in on a plot created with PLOTYY in MATLAB 7.8 (R2009a)?
12 views (last 30 days)
Show older comments
I have a plot creates with PLOTYY with dateticks and I would like the ticks to update as I zoom in on the plot.
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x,y1,x,y2,'plot');
datetick('x',20,'keeplimits');
Currently the dateticks do not update properly when I zoom and the x-axes has two sets of ticks that are overlapping.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The PLOTYY function creates two axes and the call to DATETICK in this case will only update the second axis with the dateticks. To workaround this issue, you can delete the xTicklabels on both axes and then update one of the axes with the dateticks as follows:
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x,y1,x,y2,'plot');
set(AX, 'xTickLabel','') %delete the xTicklabels
datetick(AX(1),'x',20,'keeplimits'); % create dateticks on the first x-axis
axis tight
To update the dateticks on every call to the ZOOM function, specify the 'ActionPostCallback' property of the ZOOM function:
h = zoom(gcf);
set(h,'ActionPostCallback',{@mypostcallback,AX});
set(h,'Enable','on');
Here the mypostcallback function updates dateticks on the first axis on every zoom.
function mypostcallback(obj,evd,AX)
datetick(AX(1),'x',20,'keeplimits'); % update dateticks on the 1st axis
0 Comments
More Answers (0)
See Also
See Also
Categories
Find more on Two y-axis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!