Remove or hide the special Y-axis label

조회 수: 3 (최근 30일)
Lupin Remus
Lupin Remus 2019년 4월 24일
댓글: Steven Lord 2019년 4월 24일
I have generated some sample data. These are probabilities. My problem with the graphics is that 1.01 is displayed on the Y-axis. But there is no probability that is 1.01. Nevertheless I would like to have this free place. Because if the scaling only goes to 1, then the dots are right at the bottom of the graph, which does not look that good.
Here is my code example:
clear all
clc
x = 2:1:7
y = [1 0.945312500000000 0.961318969726563 0.999182315543294 0.996585680786799 0.999999999320726]
plot(x,y,'o','MarkerSize',5,...
'MarkerEdgeColor','b',...
'MarkerFaceColor','c')
axis([0 8 0.94 1.01])
grid on

채택된 답변

Star Strider
Star Strider 2019년 4월 24일
Change your axis call to:
axis([0 8 0.94 1])
That should do what you want.
  댓글 수: 7
Star Strider
Star Strider 2019년 4월 24일
Your 'XTick' values only go from 0 to 8 since you coded them as such. However if you want to use [0 3 6 9], this will plot part of them:
xtix = [0 3 6 9];
set(gca, 'YTick',yt(1:end-1), 'YTickLabel',sprintfc('%.2f',yt(1:end-1)), 'XTick',xtix)
Otherwise, do the same as I did with the 'YTick' and 'YTickLabel' variables to put and name the x-ticks as you like, or change your axis call to go from 0 to 9 on the x-axis.
Steven Lord
Steven Lord 2019년 4월 24일
FYI as of release R2016b there are functions xticks, xticklabels, and xtickformat (as well as the corresponding Y and Z axis versions) to help make this type of customization task easier.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by