How to set a XTickLabel on a plot

조회 수: 1 (최근 30일)
jjlivestrong
jjlivestrong 2012년 9월 26일
I am trying to set a specific xlabel on a plot using set commands, but I can't get it to work.
The graph goes like this:
TODAY = datenum([2012 9 21 7 0 0]); REST_OF_TODAY = datenum([2012 9 21 17 0 0]); y_max1 = max([5,10]); y_min1 = min([5,10]); y_max2 = max([6 11]); y_min2 = min([6 11]);
plot(TODAY,y_max1,'--ys','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','g','MarkerSize',10) hold on plot(TODAY,y_min1,'--ys','LineWidth',2,'MarkerEdgeColor','b','MarkerFaceColor','y','MarkerSize',10) plot(REST_OF_TODAY,y_max2,'--ys','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','g','MarkerSize',10) plot(REST_OF_TODAY,y_min2,'--ys','LineWidth',2,'MarkerEdgeColor','b','MarkerFaceColor','y','MarkerSize',10) set(gca,'XTick',TODAY:REST_OF_TODAY) set(gca,'XTickLabel',{'Today','Rest of today'}) datetick('x',1) title('Wind(Knots) versus Time (dd-mmmm-yyyy)','fontsize',12,'fontweight','b'); xlabel('Time (dd-mmmm-yyyy)','fontweight','b'); ylabel('Wind (Knots)','fontweight','b'); grid minor
and I want it to write "TODAY" AND "REST OF TODAY" on the xaxis like the following.
t0 = 1 t1 = datenum([2012 9 21 7 0 0]) % 7 am today t2 = datenum([2012 9 21 17 0 0]) % 5 pm x = linspace(t1,t2); % generates a row vector y of 100 points linearly spaced between and including t1 and t2. plot(x,sin(sqrt(x-t0)*pi)) set(gca,'XTick',[t1,floor(t1)+0.5],'XTickLabel',{'Today','Rest of today'}) grid minor
Also, I would like them to be in bold
Can you please help?
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 26일
format your code
Star Strider
Star Strider 2012년 9월 26일
... also, what do you mean by ‘can't get it to work’?
What is it doing and what do you want it to do?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by