How can I delete last Yticklabel?
3 次查看(过去 30 天)
显示 更早的评论
I don't need my last Yticklabel so how can i delete this? And I need matlab to do labelling automatically.
0 个评论
回答(3 个)
Adam
2016-10-13
编辑:Adam
2016-10-13
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 个评论
Star Strider
2016-10-13
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 个评论
KXS
2019-7-4
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 个评论
另请参阅
类别
在 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!