Calling linkaxes on uiaxes objects makes plot contents disappear when using uigridlayout
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ted Londner
el 5 de Jun. de 2024
Comentada: Ted Londner
el 7 de Jun. de 2024
I wish to link the windows of a set of uiaxes. For regular axes objects, I would call the linkaxes function to link their windows together. In the following example, calling the linkaxes function for uiaxes objects makes any plots on these axes disappear:
% Generate UIFigure
ufig = uifigure;
% Apply grid layout to UIFigure
gl = uigridlayout(ufig, 'RowHeight', {'1x', '1x', '1x'}, 'ColumnWidth', {'1x'});
% Create three uiaxes objects; place them in the grid layout
ax1 = uiaxes(gl);
ax1.Layout.Row = 1;
ax2 = uiaxes(gl);
ax2.Layout.Row = 2;
ax3 = uiaxes(gl);
ax3.Layout.Row = 3;
% Create plots for each uiaxes object
x = 1:10;
plot(ax1, x, x);
plot(ax2, x, x.^2);
plot(ax3, x, x.^3);
% Attempt to link the uiaxes together
linkaxes([ax1 ax2 ax3]);
It is the last line of this code (with linkaxes) that makes the plots disappear. Otherwise, they show up as expected.
I believe the use of uigridlayout is contributing to the problem. In the following code snippet, which does not include the use of uigridlayout, linking the uiaxes objects together with linkaxes does not make the plots disappear:
% Generate UIFigure
ufig = uifigure;
% Create three uiaxes objects; place them side by side
ax1 = uiaxes(ufig, 'Position', [ 0 0 200 200]);
ax2 = uiaxes(ufig, 'Position', [200 0 200 200]);
ax3 = uiaxes(ufig, 'Position', [400 0 200 200]);
% Create plots for each uiaxes object
x = 1:10;
plot(ax1, x, x);
plot(ax2, x, x.^2);
plot(ax3, x, x.^3);
% Attempt to link the uiaxes together
linkaxes([ax1, ax2, ax3]);
I would appreciate any assistance that one could offer to help me understand and, if possible, correct this issue.
2 comentarios
Adam Danz
el 6 de Jun. de 2024
Editada: Adam Danz
el 6 de Jun. de 2024
I was able to reproduce the problem in R2023b but not in R2024a. It appears that linkaxes is executed before the line objects affect the axes limits.
When linkaxes is called, the axes limits (xlim, ylim) are set to manual which means they won't update. This appears to happen too early and the axes limits are set at their default values [0,1] rather than first expanding to the extent of the line.
If you run the code except for the linkaxes line and then run the linkaxes line afterwards, everything is fine because the axes limits have been correctly updated.
The easiest workaround is to put a drawnow before linkaxes so the line is rendered and the axes limits are adjusted before linkaxes takes affect, as explained in the answer below.
Respuesta aceptada
Matlab Pro
el 6 de Jun. de 2024
Hi @Ted Londner
This is really wierd! well, I tried your code.
It looks like some rendering problem..
Anyhow - add the next 2 lines to the code, just before the linkaxes - and.. you'll see tha magic happening ...
ufig.focus();
drawnow();
3 comentarios
Matlab Pro
el 6 de Jun. de 2024
I expected that drawnow() will be the answer, but (in my testing for the exact problem above) - did not suffice... just after adding the focus() - the plot was updated..
Más respuestas (1)
Zinea
el 7 de Jun. de 2024
The issue of the plots not visible is due to the scaling of the axes. The figure on executing the code snippet 1 (as given by you) is as follows:
The plots are not visible here. But if you zoom out, the plots are visible, and you get the following:
NOTE: This issue arises in MATLAB R2023b as the y axis has default tick labels at 0.1, 0.2, ..., and so on. But in MATLAB R2024a, the axis ticks are auto scaled and the plot is visible, without the need to zoom out.
Hope it helps!
Ver también
Categorías
Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!