uifigure() laggy with multiple axes, figure() does not support scrollable components
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I made an interface to display data from multiple measurement channels. It's using a Grid Layout Manager, so the first column with fixed pixel width contains channel options, and the second column with "1x" width has axes displaying data. It is Y-scrollable so it can display many channels no matter the window size.
But it gets laggy and possibly unusable when displaying just 10 channels. But I actually found that displaying the same amount of channels in a figure() window is not laggy at all.
But figure() does not support Grid Layout Manager, nor scrollable uipanel...
nb_points = 50e3;
nb_linesperaxes = 1;
nb_axes = 15;
fig = figure("Name","figure()");
fig_ax = arrayfun(@(k)axes(fig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),...
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),...
fig_ax,'UniformOutput',false);
linkaxes(fig_ax,'x')
zoom(fig_ax(1),'xon')
pan(fig_ax(2),'xon')
uifig = uifigure("Name","uifigure()");
uifig_ax = arrayfun(@(k)axes(uifig,"OuterPosition",[0,1-k/nb_axes,1,1/nb_axes]),...
1:nb_axes);
arrayfun(@(ax)plot(ax,linspace(0,1,nb_points),randn(nb_points,nb_linesperaxes)),...
uifig_ax,'UniformOutput',false);
linkaxes(uifig_ax,'x')
zoom(uifig_ax(1),'xon')
pan(uifig_ax(2),'xon')
The figure() window works wells, whereas the uifigure() window is laggy. Once compiled as app, it's even unusable on some not-too-old computers.
- Is there an alternative to Grid Layout Manager or scrollable Panel for figure() windows ?
- Is there any way to prevent uifigure() window being this laggy ?
3 Kommentare
William Dean
am 3 Mai 2024
I see, it sounds like your problem might lie with linking the axes, rather than the scrolling. In my experience, linking more than a few axes with linkaxes() can cause issues, especially if it is part of a more complicated app with many components.
However, when I tested your uifigure code section, it ran just fine. Didn't seem laggy to me. But if you have more than 15 axes I can see how it could be.
You might just have to find another method that doesn't use linkaxes().
Antworten (1)
Sandeep Mishra
am 13 Aug. 2024
Hello Guillaume,
I understand that you are trying to make an interface to display data from multiple measurement channels and seeking assistance regarding the following queries:
- Is there an alternative to Grid Layout Manager or scrollable Panel for “figure” windows?
- Is there any way to prevent “uifigure” window being this laggy?
Addressing your first query regarding the MATLAB “figure” component.
- To implement scrollable functionality in the "figure" component, the component should be placed in a scrollable container, such as a "uifigure" or another panel.
- Refer to the following MATLAB Answers post on using scrollable panel in the “figure” component: https://www.mathworks.com/matlabcentral/answers/593221-how-can-i-efficiently-plot-a-large-amount-of-graphs-stacked-in-a-scrollable-manner-within-a-panel#answer_494146
Regarding your second query, to use the “uifigure” component without laggy nature.
- I ran the provided code snippet in MATLAB R2024a and observed similar laggy nature of the “uifigure” component.
- As @William Dean already explained in the comments, the issue came around due to the multiple axes linked using “linkaxes” function.
- You can refer to the below workaround to fix the laggy nature by using “listener” and “callback” functions instead of the “linkaxes” function.
% Function to synchronize XLim of all axes
function syncXLim( ~, event, uifig_ax)
newXLim = event.AffectedObject.XLim;
for ax = uifig_ax
if ~all(ax.XLim == newXLim)
ax.XLim = newXLim;
end
end
end
% Add listener to each axis
for ax = uifig_ax
addlistener(ax, 'XLim', 'PostSet', @(src,evnt)syncXLim(src,evnt, uifig_ax));
end
Refer to the following documentations for more details on the functions used.
- “addlistener”: https://www.mathworks.com/help/releases/R2024a/matlab/ref/handle.addlistener.html
- “Listener Callback Syntax”: https://www.mathworks.com/help/releases/R2024a/matlab/matlab_oop/listener-callback-functions.html
I hope this helps.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Develop uifigure-Based Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!