Bug in axes when setting limmode. Is this a general issue when updating graphics objects?

3 views (last 30 days)
Hello dearest MathWorks-Team,
I have some odd behaviour in a minimal example I actually created for a different purpose.
In this piece of code, I get different axis limits depending on the breakpoint I am using while debugging. I'd expect the limits to be chosen so that all data is visible. But that is only the case if breakpoint 1 is active. It also does not occur if I place a pause(1) after creating the scatter-plot.
R2020b, Win10
It feels like processes are started faster, than figures can update. Some sort of threading issue.
fig = figure;
ax = axes;
% data
pdata = [sin(linspace(0,1,100)*2*pi)',cos(linspace(0,1,100)*2*pi)',sin(linspace(0,1,100)*2*pi)'];
% scatter plot with color
s = scatter3(pdata(:,1),pdata(:,2),pdata(:,3));
s.CData = sin(linspace(0,1,100)*2*pi)';
% create colorbar
c = colorbar; % breakpoint 1
c.LimitsMode = 'manual';
c.TicksMode = 'manual';
ax.XLimMode = 'manual';
ax.YLimMode = 'manual';
ax.ZLimMode = 'manual';
lengthDataHistory = 5;
nFrame = length(s.XData)-lengthDataHistory; % breakpoint 2

Answers (1)

Steven Lord
Steven Lord on 8 Aug 2023
I don't believe this is a bug. You just haven't given MATLAB a chance to update figures and process callbacks since you have neither a breakpoint nor a pause in your code. But both those options interrupt the flow of your code, so I'd use the non-disruptive drawnow function instead (perhaps with the 'limitrate' option.)
Looking at the list of actions that are equivalent to drawnow in the "More About" section of that page, pause is explicitly listed (which is why, as you noted, it works to let MATLAB update the graphics objects.) Breakpoints aren't explicitly listed, but both "Returning to the MATLAB prompt" and keyboard (to enter debug mode) are listed.
  2 Comments
Max Bartholdt
Max Bartholdt on 8 Aug 2023
Thank you for the quick answer! It feels a little clumsy, that the user has to manually pause the execution to ensure this does not happen, but I guess, if that was an easy fix you probably would have done it by now.
Steven Lord
Steven Lord on 8 Aug 2023
You don't have to manually pause. Just put drawnow in your code when you want to tell MATLAB "Go ahead and update the graphics if you need to." Otherwise it'll focus on running the code and won't take a breath to tell the graphics "Go ahead and update."

Sign in to comment.

Categories

Find more on Graphics Object Properties in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!