how to arrange xtick position.
조회 수: 11 (최근 30일)
이전 댓글 표시
sir i want to set xtick(months) at 0 then how will do this and also want to remove lower,upper horizontal line and right vertical line. how will do this .please help me. my code is this
x = [1:12];
y = [0.2208 -0.2125 0 0.0056 0.0367 2.7150 -3.0450 -10.5039 -7.6274 0 0 0];
figure;
bar(x,y,'k');
%bar(y,'g','EdgeColor',[1,0.5,0.5]);
axis([0 12 -11 11]);
title('Trend of Rainfall by Mann-Kendall for 16 Years','fontSize',16,'fontWeight','bold','FontName','Arial');
months = { 'Jan' 'Feb' 'Mar' 'Apr' 'May' 'Jun' 'Jul' 'Aug' 'Sep' 'Oct' 'Nov' 'Dec'};
xlabel('\fontname{Arial}Months','fontSize',12,'fontWeight','bold','FontName','Arial');
ylabel('\fontname{Arial}Z-Statistics','fontSize',12,'fontWeight','bold','FontName','Arial');
set(gca, 'xTickLabel', months)
thank you in advance

댓글 수: 0
채택된 답변
Geoff Hayes
2014년 5월 26일
If you want the first month (Jan) to start closer to zero, the placement of the x-axis ticks must be adjusted. The default width of any bar (in your plot) is 0.8 (type help bar in the command window for details on width) and since the mid-point of the bar lines up with ticks, then x has to be adjusted as follows so that the left-edge of the January bar lines up with zero:
halfBarWidth = 0.4;
x = halfBarWidth:1:12 % values = 0.4, 1.4, 2.4,…,11.4
(If you decide to change the bar widths, then the above should be modified accordingly.) Then, just prior to setting the x-tick labels, set the x-tick positions:
set(gca,'xTick',x);
set(gca, 'xTickLabel', months);
The above lines up the first bar with 0. If you want to line up the right-most edge of the December bar, then you will have to adjust your limits to something like:
axis([0 x(end)+halfBarWidth -11 11]);
The second part of your question is to the horizontal and vertical lines. Presumably this means the x-ticks and y-ticks (but not their labels). To do this, just set the tick length to zero:
set(gca,'TickLength',[0 0])
Hope that the above helps!
댓글 수: 4
Geoff Hayes
2014년 5월 27일
Just manipulate the x coordinate portion of
text(x-halfBarWidth/2,zeros(1,12)-1,months);
Change the x-halfBarWidth/2 to x and go from there.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
