Very slow graphics when mouse pointer moves around a figure
Ältere Kommentare anzeigen
I've got a little widget that animates a sequence of images by calling the "image()" function repeatedly with new images in a sequence. Normally the animation proceeds reasonably fast around 50-60 frames per second. However, if the mouse is in the figure window and moves around (not even clicking on anything), then the animation slows to a crawl (about 2-3 frames per second) as long as the mouse moves in the figure window. (See code at bottom for simple example to replicate this).
I've checked to ensure that the 'WindowButtonMotionFcn' figure callback is disabled (as are all other figure callbacks). I can't find any other figure, axes or even image objects that might be triggered by mouse motion in the figure window.
If I run the profiler and compare results with and without the mouse moving around the figure window, I see the function:
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
(and its dependent functions ) is getting called thousands of times and is consuming 90% of the runtime when the mouse is moving around I tried turning off both the figure's toolbar and the figure's menu bar, e.g:
hFigure.ToolBar = 'none';
hFigure.MenuBar = 'none';
and that slightly alleviates the issue somewhat, but not much (perhaps 10-20% better) . Further, even with the toolbars turned off, the profiler still indicates that
ToolbarController.ToolbarController>@obj.handleMouseMotion
is still consuming 90% of the run time whenever the mouse is moving around. There also is the function
AxesToolbarButton.AxesToolbarButton>AxesToolbarButton.AxesToolbarButton
that is also getting called thousands of times and is consuming some of the time. So I also disable the AxesToolbar by:
axesTB = get(hAxes,'ToolBar');
axesTB.visible = 'off';
axesTB.BusyAction = 'cancel';
(Unlike the figure toolbar, there doesn't seem a setting to completely disable a AxesToolbar). Anyway, turning off the axesTB didn't seem to help.
% This code can be used to illustrate the issue of slowly updating graphics.
% Run this, and then move the mouse around the figure window.
for loop=1:500
image(rand(300,300),'CDataMapping','scaled');
drawnow;
end
%Clearing the axes with "cla" before the image() call doesn't change the result. However, this version of the code is seemingly NOT impacted by this issue or very little:
hImg = image(rand(300,300),'CDataMapping','scaled');
for loop=1:500
hImg.CData = rand(300,300);
drawnow;
end
In the latter case, the profiler say that the function
ToolbarController.ToolbarController>@(e.d)obj.handleMouseMotion
still gets called a whole bunch of times but it ends up only consuming about 15% of the runtime (not 90+%), and the animation proceeds at 50+ FPS. So there is something about the combination of a moving mouse and creating new objects (rather than changing attributes of existing objects) that seems to grind matlab graphics to a halt. While I clearly point out a workaround for my little example above, in the general case, such workarounds are not always possible. It seems odd that moving a mouse while drawing objects in a figure shouldn't necessarily slow down things as much as it appears to do.
Thoughts appreciated.
9 Kommentare
Peter Lyngø Sørensen
am 12 Jan. 2021
I don't have the solution, but I want to add that I have the same problem in a GUI. Much better performance for older MATLAB versions. This problem has been there for years now, why not make it possible to disable any toolbarcontroller for GUI applications?
Maunas Mehta
am 11 Apr. 2021
I have the same Issue.
it takes for ever and i have a dedicated graphics card and 20GB ram
Simon Walker
am 17 Jun. 2021
Also can't help, but just want to add that I've had problems with this too. I have a GUI that displays live feeds from two USB cameras. The framte rate drops and it crashes regulalrly whenever the mouse is moved, making it unusable.
Would be great if someone found a solution to it.
Jonas Leuermann
am 7 Jul. 2021
I also have the same issue with my GUI.
Marios Hadjipanayi
am 25 Sep. 2021
Verschoben: Adam Danz
am 3 Okt. 2022
I have this problem too, please if anyone can help
Stefan Bleeck
am 30 Sep. 2022
I have the problem too, only worse: once the mouse enters the window, the processing drops 90% ish, and doesn't recover, even when the mouse has left the window!
I am using Matlab 2022b, but the problem has been here for at least 5 years. Never found a solution... Help appreciated!
There should be a simple way of switching off 'mouseover'...
Adam Danz
am 3 Okt. 2022
Please contact tech support and attach your app and include instructions how to reproduce the problem. Feel free to include the URL of this thread.
Johannes Herb
am 22 Feb. 2023
I am having the same issue, is there any kind of solution by now?
Piero
am 9 Mär. 2023
I've a problem which probably has the same root. In my GUI I'm updating an image within an axes (also at a resaonable slow frame rate - 4 FPS) and if I hover it with mouse during such update, depending on the moment, it fails updating resulting in blank image. I'm not creating an object, but just changing its attribute .CData. All the underlaying data are safe, so I can't catch any issue to solve. I've also disabled axes Interactions and made axes toolbar not visible, but it didn't help.
Please help.
Antworten (2)
Kelly Jantzen
am 11 Mär. 2023
I had a similar problem while plotting data that was streaming in real time. Any movement of the mouse over the uiaxes interuppted the plotting. After searching online for how others addressed the issue, I found that the combination of uiaxes settings illustrated in the following code snippet worked perfectly for my application.
%
f = uifigure();
my_axis = uiaxes(f);
my_axis.XLimitMethod = 'tight';
my_axis.Interactions = [];
my_axis.PickableParts = 'none';
my_axis.HitTest = 'off';
I hope this works for you!
3 Kommentare
Stefan Bleeck
am 13 Mär. 2023
thanks! That works! it still freezes, when the mouse moves, but will resume when still. It does the job! :)
Kelly Jantzen
am 13 Mär. 2023
BTW, I also found it necessary to initialize a single graphics object (an image in your case) prior to streaming and then update that objects properties during animation rather than creating a new object on each iteration. It speeds up plotting dramatically and (as you mention above) reduces teh impact of callbacks to mouse move events.
Martin Domeny
am 28 Jul. 2023
Thank you. Works like a charm.
Jessa
vor etwa 12 Stunden
Hi Peter -- you tracked this down well. The old hover-based axes toolbar was continuously tracking mouse position to decide when to show and hide itself, and that was causing your performance issue.
For anyone experiencing similar issues, in MATLAB R2026a, the axes toolbar was redesigned and no longer tracks mouse motion, so this source of overhead should be eliminated and you should no longer see the performance hit when moving your mouse.
However, if you are on an earlier version of MATLAB and need to remove the toolbar entirely you can simply call the following (the toolbar still gets created if you turn off the visibility, but this stops it from being created at all):
ax.Toolbar = [];
More details on the redesign: https://blogs.mathworks.com/graphics-and-apps/2026/05/04/an-accessible-modern-axes-toolbar/
Kategorien
Mehr zu Environment and Settings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!