xtick string with plot yy

4 visualizaciones (últimos 30 días)
Richard
Richard el 27 de Mzo. de 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?

Respuesta aceptada

Honglei Chen
Honglei Chen el 27 de Mzo. de 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);

Más respuestas (2)

Wayne King
Wayne King el 27 de Mzo. de 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 comentarios
Richard
Richard el 27 de Mzo. de 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 el 27 de Mzo. de 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.

Iniciar sesión para comentar.


Thomas
Thomas el 27 de Mzo. de 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])

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by