I've specified axis limits manually, why do they resize during animation?
35 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Image Analyst
il 6 Nov 2017
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]);
0 Commenti
Vedere anche
Categorie
Scopri di più su Animation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!