Effacer les filtres
Effacer les filtres

xtick string with plot yy

4 vues (au cours des 30 derniers jours)
Richard
Richard le 27 Mar 2012
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?

Réponse acceptée

Honglei Chen
Honglei Chen le 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);

Plus de réponses (2)

Wayne King
Wayne King le 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 commentaires
Richard
Richard le 27 Mar 2012
This doesn't work as I was expecting. In the example above the time along the xaxis is from 00:00 to 05:00 instead of to 23:00. Am I missing something really basic here?
Wayne King
Wayne King le 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.

Connectez-vous pour commenter.


Thomas
Thomas le 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])

Catégories

En savoir plus sur Two y-axis dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by