How to reduce space between ylabel and y ticks in Matlab plot?

How to reduce the space between y-label and y-ticks, in other words how to closer the y-label to y-axis.

 Respuesta aceptada

Subhodh Sharma
Subhodh Sharma el 25 de Sept. de 2021
Editada: Subhodh Sharma el 25 de Sept. de 2021
You can use the below command..
ylh=ylabel('ylabel'); % adding ylabelto figure
dy=0.2;
ylh.Position(1)=ylh.Position(1)-dy; % you can change 'dy' according to your need. dy=+ve, will move the label from y axis. dy=-ve , will move the label closer to the axis.

3 comentarios

Thank you very much for your response,
I got the following error
Attempt to reference field of non-structure array.
Error in graphs_codes (line 21)
ylh.Position(1)=ylh.Position(1)- dy;
Are you using R2015a or earlier? That would be important information to know for the purposes of this question !!
I'm using R2013a

Iniciar sesión para comentar.

Más respuestas (1)

yanqi liu
yanqi liu el 26 de Sept. de 2021
Editada: Walter Roberson el 26 de Sept. de 2021
sir, my be you can ref the follow code, please check
clc; clear all; close all;
figure;
ezplot('y=sin(x)');
pause(0.1);
hs = get(gca, 'XLabel');
pos = get(hs, 'Position');
pos(2) = pos(2)+0.2;
set(hs, 'Position', pos)
hs = get(gca, 'YLabel');
pos = get(hs, 'Position');
pos(1) = pos(1)+0.2;
set(hs, 'Position', pos)

4 comentarios

@yanqi liu sorry but it the above code disappear both x and y label in my case
Walter Roberson
Walter Roberson el 26 de Sept. de 2021
Editada: Walter Roberson el 26 de Sept. de 2021
how_much_to_move = 0.1;
ezplot('y=sin(x)');
hs = get(gca, 'YLabel');
pos = get(hs, 'Position');
pos(1) = pos(1) + how_much_to_move;
set(hs, 'Position', pos)
adjust how_much_to_move as needed for your purposes.
Yes, sir, this is good idea
Thank you very much, but its work for ezplot,
I want to do it for plot(x,y,..)
How can I use above for that?

Iniciar sesión para comentar.

Categorías

Productos

Versión

R2013a

Preguntada:

el 25 de Sept. de 2021

Comentada:

el 27 de Sept. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by