Bug in axes when setting limmode. Is this a general issue when updating graphics objects?
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Steven Lord
2023-8-8
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 个评论
Steven Lord
2023-8-8
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."
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!