필터 지우기
필터 지우기

Datetick showing too few data labels in a plot

조회 수: 3 (최근 30일)
Jim O'Doherty
Jim O'Doherty 2015년 6월 18일
댓글: Jim O'Doherty 2015년 6월 19일
Hi,
I've got some data I'm reading into Matlab from a txt file which contains times, which I am plotting in a GUIDE figure. I convert the times to datenums
x=datenum(times, 'HH:MM:SS');
set(handles.axes1,'Xtick',x);
handles.axes1.XTickLabelRotation = 90;
handles.plot1=semilogy(x,y)
datetick('x','HH:MM')
When I plot the graph this way, my Xtick labels are by default spaced 1 hour apart (I have 24 hours of data in 1 file), so when I zoom in, I can still only see labels that are an hour apart
1. Is there an easy way to be able to show the labels for every 30 minutes (or basically for every X minutes)
I tried
datetick('x','HH:MM', 'keeplimits', 'keepticks')
which I imagine is trying to write every tick for every x value and causes a crash (there are 80,000 datapoints)
2. Using the default figure magnifying glass, is there a way to automatically update the ticklabels so my x-axis doesn't look blank when I zoom in?
Thanks! Jim

답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 18일
datetick('x','HH:MM', 'keeplimits', 'keepticks') says to keep the existing ticks, which were either automatically generated or which you set yourself. MATLAB generally goes for 4 to 5 tick labels automatically, with an algorithm for determining which ticks might be "nice" based upon the data values. Given datenums the automatic ticks might be (for example) every 5 days; the 'keepticks' says not to recalculate to find "nice" values in the new label scheme requested.
To avoid the problems you are having with zooming in, you need to set a zoom callback and have it examine the zoom limits and decide where to put the ticks and how to label them and set() those properties .
As the above is a nuisance, the new datetime objects, when used as x coordinates, have automatic refinement for labels to automatically shift down to hours or minutes or whatever according to the zoom. If you are using R2014b or later then you may wish to switch to datetime objects.
  댓글 수: 1
Jim O'Doherty
Jim O'Doherty 2015년 6월 19일
Thanks Walter, I'll give this a go as I'm using 2014b.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by