How to plot some xtickslabel that correspond to y data?
이전 댓글 표시
Hello!
I've read a lot of answers about xticklabel and datetick, but i'm very confusing yet.
I have two vectors of 30 points.
y = 30 points
x = 30 points type date string (i've used datestr() from a datenum() number) (HH:MM:SS.FFF). See like this:
' 06:22:19.041'
' 06:22:19.048'
' 06:22:19.050'
' 06:22:19.055' ...
I used the plot function only for the y data:
plot(y);
The x data on the graphic was = 1...5...10...15...20...25...30. (7 numbers!)
So, i changed the xtickslabels:
set(gca, 'XTickLabel', x);
And the xtickslabels changed for the only the first 7 numbers of my x vector.
I need plot few points, as i did, but the points on xticks have to correspond to the y data.
Thanks. Sorry about the language
답변 (1개)
Walter Roberson
2012년 12월 12일
set(gca, 'XTick', 1:length(x), 'XTickLabel', x);
댓글 수: 10
Arthur
2012년 12월 12일
Walter Roberson
2012년 12월 12일
I suggest you take a different approach.
Let xdatenums be the datenum values, not converted to strings. Then,
plot(xdatenums, y);
datetick( 'x', 'HH:MM:SS.FFF');
Arthur
2012년 12월 12일
편집: Walter Roberson
2012년 12월 12일
Walter Roberson
2012년 12월 12일
Don't worry about how big those values for f are. You might want to give the command
format long g
to read them more naturally.
Do not issue the "hold" until after you have done the first plot.
Arthur
2012년 12월 12일
Walter Roberson
2012년 12월 12일
That appears to be the same URL as before you moved the "hold"
f = datenum(t_event_agreg{i,1},'HH:MM:SS.FFF');
figure(i)
plot(f,v_fase_a_evento_agreg{i,1},'LineWidth',2, 'Color','r');
hold on %moved to here!
plot(f,v_fase_b_evento_agreg{i,1},'LineWidth',2, 'Color','bl');
plot(f,v_fase_c_evento_agreg{i,1},'LineWidth',2, 'Color','k');
datetick('x', 'HH:MM:SS.FFF');
grid minor;
title(['Evento Agregado n.: ',num2str(i)])
xlabel ('Tempo [MM:SS.FFF]');
ylabel ('Magnitude da Tensão de Fase [%]');
ylim([0 120]);
legend('Fase A','Fase B','Fase C')
Arthur
2012년 12월 12일
Walter Roberson
2012년 12월 12일
Interesting! The lower level graphics are imposing a minimum distance between xlim boundaries of approximately 1/6000 whereas your data is many times finer grained than that. setting xlim manually did not help, even with XLimMode set to 'manual': the graphics overrides it.
So....
dv = datevec(f);
x = dv(:,6);
plot(x, y)
The result will be in milliseconds (only), corresponding to the fact that your data values are a fraction of a millisecond apart. If you want to include seconds, you can make a calculation such as
x = dv(:,5) + dv(:,6)/ 1000;
but be warned that your f are close enough together that the tick labels might not all be different. It is possible to increase the precision of the tick labels with
set(gca, 'XTickLabel', num2str(get(gca, 'XTick').', '%.6f'))
Arthur
2012년 12월 13일
Arthur
2012년 12월 13일
카테고리
도움말 센터 및 File Exchange에서 Axes Appearance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!