How can I delete last Yticklabel?
3 views (last 30 days)
Show older comments
I don't need my last Yticklabel so how can i delete this? And I need matlab to do labelling automatically.
0 Comments
Answers (3)
Adam
on 13 Oct 2016
Edited: Adam
on 13 Oct 2016
Do you mean just the label or the actual tick too?
If you want Matlab to still auto label them if you allow anything to happen on your plot that can change the axes limits (e.g. zooming, panning, data changing) you will likely have to attach a listener to the YTick property and respond in there.
What to do to remove the tick is trivial.
hAxes.YTickLabel{end} = []
will remove just the tick label.
hAxes.YTick(end) = []
will remove the tick. If you want to remove the tick then just do that and the label will be removed automatically.
Note: The above syntax assumes R2014b or later.
addlistener( hAxes, 'YLim', 'PostSet', @(src,evt) disp( 'Hello' ) )
is an example of adding a listener to an axes property. Just replace that simple function handle with one of your own that does either of the above two statements. You will have to define it in a separate function and create a function handle to it.
0 Comments
Star Strider
on 13 Oct 2016
One approach:
figure(1)
plot(rand(1,100), rand(1, 100), 'bp') % Create DAta & Plot It
grid
ytix = get(gca, 'YTick'); % Y-Tick Values
ytixlbl = get(gca, 'YTickLabel'); % Y-Tick Labels
set(gca, 'YTick',ytix(1:end-1), 'YTickLabel',ytixlbl(1:end-1)) % Omit Last Y-Tick Label
0 Comments
KXS
on 4 Jul 2019
figure(1)
plot(rand(1,100),rand(1,100))
hold on
ylim([min max])
set(gca,'YTick',(min:int:max-1)) %note that min,int and max are integers
% also work in X labels
0 Comments
See Also
Categories
Find more on Axis Labels 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!