필터 지우기
필터 지우기

Ticks label problem Julian day

조회 수: 3 (최근 30일)
Emrys
Emrys 2017년 11월 3일
편집: dpb 2017년 11월 4일
Hi guys, I have a dataset with 4416 numbers. Plotting it on time series in which every numbers corresponds to an hour and it's quite ugly to see ticks every hours and I chose to put ticks every 10 days (240 ticks), Now my problem was, How can i write te corrisponding julian day to the 10th tick? or the twentieth? Imagine that the first tick is the 1 of January and the second the 10th. Can someone help me please?
  댓글 수: 1
Steven Lord
Steven Lord 2017년 11월 3일
Can you show us a small sample of the code you've written to plot the data (so we can see how it behaves) and include a small sample of data so we can try to run that code? Please also indicate what release of MATLAB you're using so we don't recommend solutions that require functionality introduced after the release you're using.

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

답변 (1개)

dpb
dpb 2017년 11월 3일
편집: dpb 2017년 11월 4일
Convert the numeric values to datetime either as time or duration depending on the meaning. You'll need to pick the appropriate year for the actual calendar date to match for leap year accounting, of course if want that level of detail.
Then plot is datetime -aware so the axes will be in time units and you can fix up the number/style of ticks as desired.
ADDENDUM
My suggestion looks something like--
t=0:4415; % time vector in hours
t=datetime(2017,1,1,t(:),0,0); % convert to datetime for specific year
plot(t,randn(size(t))) % plot using datetime-aware axes by default
xl=xlim; % retrieve default x-axis limits
xl(1)=datenum(datevec(t(1))); % set LH axis start to beginning of data
xlim(xl)
dtk=datenum(2017,[1:7].',1); % compute monthly tick spacings
set(gca,'xtick',dtk) % set tick values to those
The "trick" above is in setting the x-axis limits to match the beginning of the data exactly rather than the default that tries to space uniformly the ticks across the range. I'm still at R2014b which uses the old datenum as the internal axis variable; I believe that has since been updated to be consistent with the datetime class so can set the tick values with the same time array values as the axis itself removing one slight complexity.
With time axes, labels take a lot of real estate so may not be able to place as many ticks as can with pure numeric axes.
I'm not sure just what the timeseries actually does with plot; what little I've looked at it in R2014b it just didn't have any advantage over keeping a straight time vector for what I'd tried it for; perhaps later incarnations are more developed just as datetime continues to evolve...
  댓글 수: 1
Emrys
Emrys 2017년 11월 3일
Sorry Mr/Mrs dpb if i'm not so practical, can you give a code example? I cannot really set the problem

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

카테고리

Help CenterFile Exchange에서 Grid 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