Filter löschen
Filter löschen

xtick string with plot yy

4 Ansichten (letzte 30 Tage)
Richard
Richard am 27 Mär. 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?

Akzeptierte Antwort

Honglei Chen
Honglei Chen am 27 Mär. 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);

Weitere Antworten (2)

Wayne King
Wayne King am 27 Mär. 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 Kommentare
Richard
Richard am 27 Mär. 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 am 27 Mär. 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.

Melden Sie sich an, um zu kommentieren.


Thomas
Thomas am 27 Mär. 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])

Kategorien

Mehr zu Two y-axis finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by