how to write years in xtick.
1 回表示 (過去 30 日間)
古いコメントを表示
sir i want to write years in xtick like this figure and also write R2 value in figure how can do this? please help.thank you in advance.

0 件のコメント
回答 (2 件)
Chad Greene
2014 年 6 月 18 日
If your x vector is in datenum format, you can use datetick('x','yyyy').
0 件のコメント
Azzi Abdelmalek
2014 年 5 月 26 日
4 件のコメント
Azzi Abdelmalek
2014 年 6 月 18 日
I adapted the code from the previous link to plot x,y
% Generate some test data. Assume that the X-axis represents months.
x = 1901:3:2003
y = 10*rand(1,length(x));
% Plot the data.
h = plot(x,y);
% Reduce the size of the axis so that all the labels fit in the figure.
pos = get(gca,'Position');
set(gca,'Position',[pos(1), .2, pos(3) .65])
% Add a title.
title('This is a title')
% Set the X-Tick locations so that every other month is labeled.
Xl = [1901 2003];
set(gca,'XTick',x,'XLim',Xl);
% Add the months as tick labels.
years=cellfun(@num2str,num2cell(x),'un',0)
ax = axis; % Current axis limits
axis(axis); % Set the axis limit modes (e.g. XLimMode) to manual
Yl = ax(3:4); % Y-axis limits
% Place the teaxt labels
t = text(x,Yl(1)*ones(1,length(x)),years);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
'Rotation',90);
% Remove the default labels
set(gca,'XTickLabel','')
% Get the Extent of each text object. This
% loop is unavoidable.
for i = 1:length(t)
ext(i,:) = get(t(i),'Extent');
end
% Determine the lowest point. The X-label will be
% placed so that the top is aligned with this point.
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'X-Axis Label', ...
'VerticalAlignment','top', ...
'HorizontalAlignment','center');
参考
カテゴリ
Help Center および File Exchange で Axis Labels についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!