Remove or hide the special Y-axis label

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

 Accepted Answer

Change your axis call to:
axis([0 8 0.94 1])
That should do what you want.

7 Comments

Lupin Remus
Lupin Remus on 24 Apr 2019
Edited: Lupin Remus on 24 Apr 2019
Nearly! The problem is that the data points are right at the end. And I would like to have some free space, if you understand?
matlb.PNG
I really wanted to avoid that
Try this:
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])
yt = get(gca, 'YTick');
set(gca, 'YTick',yt(1:end-1), 'YTickLabel',sprintfc('%.2f',yt(1:end-1)))
grid on
Experiment to get the result you want.
WOW, that's impressive! That's exactly what I wanted! Thank you very much!
Thank you!
As always, my pleasure!
I would still have a little question if you have some time. I would be interested to know how to scale the X-axis differently. The value range is good, but I would like a more detailed scaling. Currently there are 5 steps (0 5 10 15 ...). Can 3 steps be mapped (0 3 6 9 ...)?
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.
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!