Setting axes in bar function

조회 수: 26 (최근 30일)
abidi Mohamed
abidi Mohamed 2014년 6월 1일
댓글: Star Strider 2014년 6월 2일
Exemple
x=0:1:20
y=1;.9999999;.9999998;.9999997;.9999996;.9999996;.9999995;.9999994;.9999993;.9999992;.9999991;.9999991;.9999991;.9999991;.9999991;.9999991;.9999991;.9999991;.9999991;.9999990;.9999990]
bar(x,y)
-----------------------------------------------
The variation of my function is very small, and the values are very precise (1e-10)
I want to customize the way in which tick labels appear in Matlab plot axes
  • 1/ modify the x and y axes limits (from min value to max value)
  • 2/ display 10 decimal digits in y and x axes

채택된 답변

Star Strider
Star Strider 2014년 6월 1일
편집: Star Strider 2014년 6월 1일
This works:
figure(1)
bar(x,y)
axis([-0.5 20.5 min(y)-2E-8 max(y)])
xt = {get(gca, 'YTick')}
for k1 = 1:10
xts{k1} = (num2str(xt{1}(k1),'%.10f'));
end
set(gca, 'YTick', cell2mat(xt), 'YTickLabel', xts, 'FontSize',7)
producing:
  댓글 수: 1
Star Strider
Star Strider 2014년 6월 2일
‘Star Strider: y0=1 not 0.999999’
Overlooked that.
Fixed now:
figure(1)
bar(x,y)
axis([-0.5 20.5 min(y)-5E-8 max(y)])
yt = {get(gca, 'YTick')}
for k1 = 1:size(yt{1},2)
xts{k1} = (num2str(yt{1}(k1),'%.10f'));
end
set(gca, 'YTick', cell2mat(yt), 'YTickLabel', xts, 'FontSize',7)

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

추가 답변 (2개)

aneps
aneps 2014년 6월 1일
편집: aneps 2014년 6월 2일
use xlim, ylim options... you can simply give
xlim=([xmin xmax]);
ylim=([ymin ymax]);
or
set(gca,'XLim',[xmin xmax]);
set(gca,'XTick',[xmin:interval:xmax]);
set(gca,'YLim',[ymin ymax]);
set(gca,'YTick',[ymin:interval:ymax]);
for decimal places
xn=get(gca,'xtick');
set(gca,'xticklabel',sprintf('%.10f |',xn));
yn=get(gca,'ytick');
set(gca,'yticklabel',sprintf('%.10f |',yn));

abidi Mohamed
abidi Mohamed 2014년 6월 1일
thank you aneps have you any solution for my second problem "display 10 decimal digits in y and x axes"
  댓글 수: 3
Star Strider
Star Strider 2014년 6월 2일
...posted 21 hours after mine...
abidi Mohamed
abidi Mohamed 2014년 6월 2일
편집: abidi Mohamed 2014년 6월 2일
aneps,Star Strider: thank you very much for your help
Star Strider: y0=1 not 0.999999

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by