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 Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by