Xtick in timeseries Plot

조회 수: 1 (최근 30일)
j_solar
j_solar 2013년 1월 17일
I am plotting a timeseries and I can't manage to choose the Xtick on it.
I automatically get values like:
05:00 05:48 06:36 07:24 08:12 ............. in the Xaxis for a days values
I would like to change it to whole values like
05:00 06:00 07:00 08:00
ty for the help

채택된 답변

owr
owr 2013년 1월 17일
This may not be the cleanest solution, but it should work well enough, or give you some ideas at least.
1) Draw your graph
Example:
x = 4.3:0.1:9.2;
y = x.^2;
plot(x,y);
2) Set the axis xtick to your specified values
xt = 5:1:8;
set(gca,'xtick',xt);
3) If you want your custom time based format, convert the xtick values to text with your specified formatting, override xtick labels
fun = @(n) sprintf('%02d:00',n);
xtl = arrayfun(foo,xt,'uniformoutput',false);
set(gca,'xticklabel',xtl);
  댓글 수: 4
owr
owr 2013년 1월 17일
If your time is measured in decimals, just sample 'xt' in 0.5 increments:
xt = 5:0.5:8
You'll then need a function that converts decimals to hours, minutes, etc.
"datevec" might do the trick if you're using serial dates for your time array:
[y,m,d,h,mn,s] = datevec(now)
Sounds like a fun project, good luck
j_solar
j_solar 2013년 1월 18일
uhm, I tried it but I don't think it works in my case.
I have an array of values every minute(1440 values from 00:00 to 23:59) and I want to plot it vs time and I want time to go every half an hour from 5:00 5:30 6:00 6:30... to 20:00.
xt must start in 300 otherwise it doesn't plot it in the right place. I have tried xt = 300:30:1200 but it doesn't work well. I think I need to change
fun = @(n) sprintf('%02d:00', n);
to add the minutes

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by