how to arrange xtick position.
23 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Geoff Hayes
on 26 May 2014
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 Comments
Geoff Hayes
on 27 May 2014
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.
More Answers (0)
See Also
Categories
Find more on Labels and Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!