Totally crazy behaviour of figures. Axes going around through the image!

6 次查看(过去 30 天)
Hello,
I'm working on a GUI in matlab and I ended up with a really strange behaviour in my code. I manage to isolate the problem in a single script, which is the following:
fig = figure('Name','Spatial modes', ...
'numbertitle', 'off', ...
'ToolBar', 'none', ...
'menu','none','units','normalized',...
'outerposition',[0 0 1 1]);
title('whatever')
for i = 1:100
set(0,'CurrentFigure',fig)
cla
imagesc(rand(10))
caxis auto
hand.im_caxis.val = caxis;
colormap hot
colorbar
axis ij equal tight
set(gca,'color','none')
title(num2str(i))
drawnow
pause(0.1)
end
If you try to run it, you will see that the axes of the figure shift to the right every time the image is updated. After a dozen of shifts, they start shrinking until they are invisible and eventually they go back to the original size.
What is going on? What am I missing?

采纳的回答

Alessandro Masullo
Alessandro Masullo 2016-8-30
I contacted the MathWorks Support and they confirmed me that this is a bug of the R2015a version.
They also suggested me a simple workaround to avoid this problem. If you experience a similar issue, try to call the colorbar line after the axis line:
axis ij equal tight
colorbar
This will prevent the axes to move randomly.

更多回答(2 个)

the cyclist
the cyclist 2016-8-26
I ran your code in R2016a, and did not have the "disappearing figure" you show. It worked fine.
  2 个评论
Alessandro Masullo
Alessandro Masullo 2016-8-26
I ran the code in matlab R2015a and the result is shown in the attached gif. Is there a bug? And if so, is there a workaround?
Walter Roberson
Walter Roberson 2016-8-30
I tested in R2015a on OS-X and do not get a shrinking plot. The labels on the colorbar move around a bit but the sizes do not change (the change in label reflects the fact that imagesc() depends upon the range of values in the data but since your data is randomly generated, the range of values changes from random matrix to random matrix.)

请先登录,再进行评论。


Image Analyst
Image Analyst 2016-8-26
I also do not observe the effect in R2016a. The best workaround is to upgrade to the latest release. Another workaround might be to get the 'Position' property of the axes the first iteration, and then use that to set it in subsequent iterations. So if it got changed somehow, that should fix it. Try adding this code:
imagesc(rand(10))
ax = gca;
if i == 1
position = ax.Position;
else
ax.Position = position;
end
  2 个评论
Alessandro Masullo
Alessandro Masullo 2016-8-29
Hello Image Analyst,
This must definitely by a bug. I tried this code:
close all force
clear
fig = figure('Name','Spatial modes', ...
'numbertitle', 'off', ...
'ToolBar', 'none', ...
'menu','none','units','normalized',...
'outerposition',[0 0 1 1]);
for i = 1:100
imagesc(rand(10))
% foo = caxis;
colormap hot
colorbar
axis ij equal tight
set(gca,'color','none')
title(num2str(i))
drawnow
pause(0.1)
end
and the figure is updated nicely. If you uncomment the line "foo = caxis;" then the image is updated in that crazy way I showed in the image.
Unfortunately, I cannot use your solution because in my code I don't have a simple for loop, but a function that updates the figure based on a callback, therefore I don't know when it is generated for the first time.
Image Analyst
Image Analyst 2016-8-30
I can't test your version, but if it was a bug then it's fixed now since I don't observe it with R2016a.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by