xtick string with plot yy
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Honglei Chen
2012-3-27
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 个评论
更多回答(2 个)
Wayne King
2012-3-27
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 个评论
Wayne King
2012-3-27
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
2012-3-27
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!