How can I delete last Yticklabel?

조회 수: 3 (최근 30일)
Dinil Bose
Dinil Bose 2016년 10월 13일
답변: KXS 2019년 7월 4일
I don't need my last Yticklabel so how can i delete this? And I need matlab to do labelling automatically.

답변 (3개)

Adam
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.

Star Strider
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

KXS
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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by