I've specified axis limits manually, why do they resize during animation?

36 次查看(过去 30 天)
I'm animating uploaded data from a GUI. The animation is a trail of data that adds new values as dark blue and old values trail off into white, they translate across S from 1->0 in HSV color space. When I run the animation from the GUI - I'm using the App Editor - the axis limits gets recalculated every frame of the animation, it's awful. But they work fine when I'm not using the GUI. Do I need to set the axes limits another way?
I specify axis limits using axis as follows
axis(1.1*[-boardWid/2 boardWid/2 -boardHei/2 boardHei/2])
Also, my code, the one that does work (from a script)
figure(1), clf
boardWid = 600;
boardHei = 400;
numtrail = 15; % amount of trailing markers
t = linspace(0,2*pi);
datax = boardWid/2 * cos(t);
datay = boardHei/2 * sin(t);
hsvcmap = [0.6*ones(numtrail,1), linspace(1,0,numtrail)', ones(numtrail,1)];
ax = scatter(datax(1:numtrail), datay(1:numtrail), [], hsv2rgb(hsvcmap), 'filled');
axis(1.1*[-boardWid/2 boardWid/2 -boardHei/2 boardHei/2])
daspect([1 1 1]) % specify axes ratio to agree with board in visual space
%%play/make the animation
%%maybe we want to make a movie instead
for frame = (numtrail+1):length(datax)
ax.XData = [datax(frame) ax.XData(1:end-1)];
ax.YData = [datay(frame) ax.YData(1:end-1)];
drawnow
pause(0.01)
end
and the code that doesn't is embedded in the mess of the app files, but here's the function that implements the animation routine.
function results = generateTrailingScatterAnimation(app, datax, datay, numtrail)
boardWid = 600;
boardHei = 400;
cla(app.UIAxes);
hsvcmap = [0.6*ones(numtrail,1), linspace(1,0,numtrail)', ones(numtrail,1)];
ax = scatter(app.UIAxes, datax(1:numtrail), datay(1:numtrail),...
[], hsv2rgb(hsvcmap), 'filled');
axis(1.1*[-boardWid/2 boardWid/2 -boardHei/2 boardHei/2])
daspect([1 1 1]) % specify axes ratio to agree with board in visual space
%%play/make the animation
%%maybe we want to make a movie instead
for frame = (numtrail+1):length(datax)
ax.XData = [datax(frame) ax.XData(1:end-1)];
ax.YData = [datay(frame) ax.YData(1:end-1)];
drawnow
pause(0.01)
end
end

采纳的回答

Image Analyst
Image Analyst 2017-11-6
MATLAB automatically adjusts the axes each time you plot or add to it. To use fixed axes, you can put hold on once they are what you like,
hold on;
or you can use the xlim() and ylim() functions.
xlim([xLow, xHigh]);
ylim([yLow, yHigh]);

更多回答(1 个)

yeungor
yeungor 2017-11-6
Figured it out how to solve the problem. But I don't know why it works, so that would be nice to get explained. If I use this,
set(app.UIAxes, 'XLim', 1.1*[-boardWid/2 boardWid/2])
set(app.UIAxes, 'YLim', 1.1*[-boardHei/2 boardHei/2])
Instead of using the axis function, then it works, but I don't understand why this is the case. Why won't axis default to the axis in the GUI window? It's the only axes on the figure and the app only has the one figure.
  1 个评论
Alex Baum
Alex Baum 2018-12-1
Near as I can tell those commands directly set the XLim and YLim properties of the axes instead of going through the axis function.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by