Why does changing ydir to 'reverse' change xdir and axis locations,... (2024)

16visualizaciones (últimos 30días)

Mostrar comentarios más antiguos

Paulina Müller el 4 de Ag. de 2016

  • Enlazar

    Enlace directo a esta pregunta

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir

  • Enlazar

    Enlace directo a esta pregunta

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir

Comentada: Paulina Müller el 4 de Ag. de 2016

Respuesta aceptada: Thorsten

Abrir en MATLAB Online

I am updating an old GUI created in 2004 (by someone else) to be usable again, and one of the main problems was that elements of the GUI overlapped: There are two plots and a set of uicontrol elements. I moved the positions of the uicontrols, but there is still overlap with the plots.

Why does changing ydir to 'reverse' change xdir and axis locations,... (2)

The left plot is Axes2, the right plot is Axes1, but the left one is used first.

The y-axis should be reversed, the x-axis normal, and the axis locations should be "left" and "bottom". The right plot is meant to have no yticklabels.

The problem, as you can probably see in the image, is that setting the Ydir-property to 'reverse' does not change the direction of the y-axis, but what happens is that Xdir is set to 'reverse' and the axis locations are changed to 'right' and 'top', and not even explicitly setting them to 'left' and 'bottom' moves them to the right place. The axis labels are also consequently in the wrong place. This is the code in the program that plots the data:

if true

% code

%%GUI laden

inversion_gui_edit; % load GUI PM

hold on

box on

patch([-1e-3 1e-3 1e-3 -1e-3 -1e-3],...

[0 0 zmax0 zmax0 0],...

[0.7 0.7 0.7],...

'EdgeColor','none');

hold on;

plot(0*ones(2,1),[0 zmess0(N0)],'k-',... % make vertical line at 0 PM

TMess,zmess0,'k:',... % plot Temperatures

TMess,zmess0,'ko'); % mark Temperatures

if (max(abs(TMess))<.1||max(abs(TMess))==.1); % || means OR

axis([-.1 .1 0 zmax0])

end;

if max(abs(TMess))>.1;

axis([-max(abs(TMess)) max(abs(TMess)) 0 zmax0])

end;

grid on;

title('T [K] with BTV and q/k=0');

ylabel('z [m]');

ax = gca

ax.YDir = 'reverse';

ax.YAxisLocation = 'left';

ax.XAxisLocation = 'bottom';

for bar0=1:N0;

barx0=[TMess(bar0)-1e-3 TMess(bar0)+1e-3];

bary0=[zmess0(bar0) zmess0(bar0)];

plot(barx0,bary0,'k-','LineWidth',2);

end;

achse=axis;

achse=achse(2);

xlabel(['Station ',FILENAME(5:6),' Pen ',FILENAME(8:9)]); %PM

H11=findobj('Tag','Axes1');

H12=findobj('Tag','Axes2');

plot(0*ones(2,1),[0 zmess0(N0)],'k-',...

kMess,zmess0,'k:',...

kMess,zmess0,'ko',...

'Parent',H11);

set(H11,'ydir','reverse');

set(H11,'YTickLabel',[]);

set(H11,'XGrid','on');

set(H11,'YGrid','on');

set(H11,'XLim',[-.5 .5]);

if max(abs(kMess))>.5;

set(H11,'XLim',[-max(abs(kMess)) max(abs(kMess))]);

end;

set(H11,'YLim',[0 zmax0]);

end

For the sake of completeness, this is how the axes are set up for the gui:

if true

% code

h1 = axes('Parent',h0, ...

'Units','pixels', ...

'CameraUpVector',[0 1 0], ...

'CameraUpVectorMode','manual', ...

'Color',[1 1 1], ...

'ColorOrder',mat8, ...

'Position',[268+5 84 148 355], ...

'Tag','Axes1', ...

'XColor',[0 0 0], ...

'YColor',[0 0 0], ...

'ZColor',[0 0 0]);

h2 = text('Parent',h1, ...

'Color',[0 0 0], ...

'HandleVisibility','off', ...

'HorizontalAlignment','center', ...

'Position',[0.4965986394557824 -0.07909604519774005 9.160254037844386], ...

'Tag','Axes1Text4', ...

'VerticalAlignment','cap');

set(get(h2,'Parent'),'XLabel',h2);

h2 = text('Parent',h1, ...

'Color',[0 0 0], ...

'HandleVisibility','off', ...

'HorizontalAlignment','center', ...

'Position',[-0.2380952380952381 0.4971751412429378 9.160254037844386], ...

'Rotation',90, ...

'Tag','Axes1Text3', ...

'VerticalAlignment','baseline');

set(get(h2,'Parent'),'YLabel',h2);

h2 = text('Parent',h1, ...

'Color',[0 0 0], ...

'HandleVisibility','off', ...

'HorizontalAlignment','right', ...

'Position',mat9, ...

'Tag','Axes1Text2', ...

'Visible','off');

set(get(h2,'Parent'),'ZLabel',h2);

h2 = text('Parent',h1, ...

'Color',[0 0 0], ...

'HandleVisibility','off', ...

'HorizontalAlignment','center', ...

'Position',[0.4965986394557824 1.022598870056497 9.160254037844386], ...

'Tag','Axes1Text1', ...

'VerticalAlignment','bottom');

set(get(h2,'Parent'),'Title',h2);

h1 = axes('Parent',h0, ...

'Units','pixels', ...

'CameraUpVector',[0 1 0], ...

'CameraUpVectorMode','manual', ...

'Color',[1 1 1], ...

'ColorOrder',mat10, ...

'Position',[51 84 179 355], ...

'Tag','Axes2', ...

'XColor',[0 0 0], ...

'YColor',[0 0 0], ...

'ZColor',[0 0 0]);

h2 = text('Parent',h1, ...

'Color',[0 0 0], ...

'HandleVisibility','off', ...

'HorizontalAlignment','center', ...

'Position',[0.4943820224719101 -0.07909604519774005 9.160254037844386], ...

'Tag','Axes2Text4', ...

'VerticalAlignment','cap');

set(get(h2,'Parent'),'XLabel',h2);

h2 = text('Parent',h1, ...

'Color',[0 0 0], ...

'HandleVisibility','off', ...

'HorizontalAlignment','center', ...

'Position',mat11, ...

'Rotation',90, ...

'Tag','Axes2Text3', ...

'VerticalAlignment','baseline');

set(get(h2,'Parent'),'YLabel',h2);

h2 = text('Parent',h1, ...

'Color',[0 0 0], ...

'HandleVisibility','off', ...

'HorizontalAlignment','right', ...

'Position',mat12, ...

'Tag','Axes2Text2', ...

'Visible','off');

set(get(h2,'Parent'),'ZLabel',h2);

h2 = text('Parent',h1, ...

'Color',[0 0 0], ...

'HandleVisibility','off', ...

'HorizontalAlignment','center', ...

'Position',[0.4943820224719101 1.022598870056497 9.160254037844386], ...

'Tag','Axes2Text1', ...

'VerticalAlignment','bottom');

set(get(h2,'Parent'),'Title',h2);

end

The blank gui looks like this and is fine:

Why does changing ydir to 'reverse' change xdir and axis locations,... (3)

I haven't got a clue why this is happening and I'd be happy for some pointers as to what I could try to fix this. Could a be an issue with the 2015b release I'm using??

0 comentarios

Mostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Iniciar sesión para responder a esta pregunta.

Respuesta aceptada

Thorsten el 4 de Ag. de 2016

  • Enlazar

    Enlace directo a esta respuesta

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#answer_230797

  • Enlazar

    Enlace directo a esta respuesta

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#answer_230797

Editada: Thorsten el 4 de Ag. de 2016

Abrir en MATLAB Online

Probably you messed up the first and the second plot. gca may give you the axes of the right plot, and then you try to reverse the invisible y-axis. I would define ax_left and ax_right referring to the left and right plot, resp., once you have created the axes, and then work on these, without using gca.

I also found out that the example works if you delete the lines

'CameraUpVector',[0 1 0], ...

'CameraUpVectorMode','manual', ...

when you create the axes. They seem to interfere with he YDir setting:

h1 = axes('Parent',h0, ...

'Units','pixels', ...

'Color',[1 1 1], ...

'Position',[268+5 84 148 355], ...

'Tag','Axes1', ...

'XColor',[0 0 0], ...

'YColor',[0 0 0], ...

'ZColor',[0 0 0]);

ax_right = h1;

h1 = axes('Parent',h0, ...

'Units','pixels', ...

'Color',[1 1 1], ...

'Position',[51 84 179 355], ...

'Tag','Axes2', ...

'XColor',[0 0 0], ...

'YColor',[0 0 0], ...

'ZColor',[0 0 0], 'YDir', 'reverse');

ax_left = h1;

ax_left.YAxisLocation = 'right';

ax_left.YDir = 'reverse';

ax_left.XTick = [];

ax_right.YTick = [];

ax_right.XLim = [-.5 .5];

2 comentarios

Mostrar NingunoOcultar Ninguno

Paulina Müller el 4 de Ag. de 2016

Enlace directo a este comentario

https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#comment_383451

  • Enlazar

    Enlace directo a este comentario

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#comment_383451

Thanks - I tried that, and it didn't help. Just to test, I also changed Ydir to reverse on the right plot, and the same thing happens...

Paulina Müller el 4 de Ag. de 2016

Enlace directo a este comentario

https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#comment_383461

  • Enlazar

    Enlace directo a este comentario

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#comment_383461

Thanks, only saw the edit just now - it works in my script too!

Iniciar sesión para comentar.

Más respuestas (1)

Steven Lord el 4 de Ag. de 2016

  • Enlazar

    Enlace directo a esta respuesta

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#answer_230803

  • Enlazar

    Enlace directo a esta respuesta

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#answer_230803

Abrir en MATLAB Online

I recommend using gca only in the Command Window while experimenting. When you write your "final" code, make sure you're operating on the axes you think you are. In this particular case, if you want to change the axes in which you plotted, get its axes ancestor and operate using that handle.

% Create two axes and plot in the first

ax1 = subplot(2, 1, 1);

ax2 = subplot(2, 1, 2);

h = plot(ax1, 1:10, (1:10).^2);

% Make the second axes active

axes(ax2);

% Change the current axes color to red

set(gca, 'Color', 'r');

% Change the axes with the plot to log scale

A = ancestor(h, 'axes');

set(A, 'YScale', 'log');

If I had clicked in another axes before changing the color to red, it would have changed the color of that axes, not the second subplot. But the last segment of code would ALWAYS (assuming that the plot and the axes that contains it still exists and that the plot hadn't been moved from one axes to the next between those last two lines of code, which would require very precise timing) change the scale of the Y axis of the axes containing the line, regardless of wherever else I had clicked.

1 comentario

Mostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Paulina Müller el 4 de Ag. de 2016

Enlace directo a este comentario

https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#comment_383462

  • Enlazar

    Enlace directo a este comentario

    https://es.mathworks.com/matlabcentral/answers/298465-why-does-changing-ydir-to-reverse-change-xdir-and-axis-locations-but-not-ydir#comment_383462

You're absolutely right, and if I were writing this from scratch it would look different ^^

Iniciar sesión para comentar.

Iniciar sesión para responder a esta pregunta.

Ver también

Categorías

MATLABGraphicsFormatting and AnnotationLabels and AnnotationsAxis Labels

Más información sobre Axis Labels en Help Center y File Exchange.

Etiquetas

  • ydir

Community Treasure Hunt

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

Start Hunting!

Se ha producido un error

No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.


Translated by Why does changing ydir to 'reverse' change xdir and axis locations,... (9)

Why does changing ydir to 'reverse' change xdir and axis locations,... (10)

Seleccione un país/idioma

Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .

También puede seleccionar uno de estos países/idiomas:

América

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia-Pacífico

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Comuníquese con su oficina local

Why does changing ydir to 'reverse' change xdir and axis locations,... (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Greg Kuvalis

Last Updated:

Views: 5615

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.