How can I delete last Yticklabel?

4 vues (au cours des 30 derniers jours)
Dinil Bose
Dinil Bose le 13 Oct 2016
Réponse apportée : KXS le 4 Juil 2019
I don't need my last Yticklabel so how can i delete this? And I need matlab to do labelling automatically.

Réponses (3)

Adam
Adam le 13 Oct 2016
Modifié(e) : Adam le 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.

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

KXS
KXS le 4 Juil 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

Community Treasure Hunt

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

Start Hunting!

Translated by