xtick string with plot yy
2 views (last 30 days)
Show older comments
From the following example how would I show the time denoted by 'out' along the xaxis:
clear all
time = (0:23)';
n = numel(time);
out = cellstr(datestr([ones(n,1)*[2012 3 10] time zeros(n,2)],'HH:MM'));
%data
data1 = rand(24,1);
data2 = rand(24,1);
plotyy(time,data1,time,data2);
I have tried
set(gca,'XTickLabel',out);
But it does not work. How would I generate a plot similar to the one shown above but with the time i.e. from 00:00 to 23:00 along the xaxis?
0 Comments
Accepted Answer
Honglei Chen
on 27 Mar 2012
replace the call to plotyy with following:
h = plotyy(time,data1,time,data2);
set(h,'XTickLabel','');
set(h,'XTick',0:23);
set(h,'XTickLabel',out);
0 Comments
More Answers (2)
Wayne King
on 27 Mar 2012
You can do something like the following, but you have a large number of ticks here... so
time = (0:23)';
n = numel(time);
out = cellstr(datestr([ones(n,1)*[2012 3 10] time zeros(n,2)],'HH:MM'));
%data
data1 = rand(24,1);
data2 = rand(24,1);
[ax,h1,h2] = plotyy(time,data1,time,data2);
set(ax,'xtick',1:3:24)
set(ax,'xticklabel',' ');
set(ax,'xticklabel',out(1:3:24));
2 Comments
Wayne King
on 27 Mar 2012
That was the problem I mentioned with the number of ticks you have, I think you have to use a subset of them. I've modified the above.
Thomas
on 27 Mar 2012
How about this?
clear all
time = (0:23)';
n = numel(time);
out = cellstr(datestr([ones(n,1)*[2012 3 10] time zeros(n,2)],'HH:MM'))
%data
data1 = rand(24,1);
data2 = rand(24,1);
[A,h1,h2]=plotyy(time,data1,time,data2);
set(A,'XTickLabel',out(1:3:24),'XTick',[1:3:24])
0 Comments
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!