Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Scatter doen not plot!
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello!
The code lines written below are inserted in a for loop. Depending on whether
my figure has been initialized or not, the former or the latter part of the code is
executed. However, after the first iteriation (where the figure is initialized),
points disappear from the figure and do not come back.
As you can see, I used the instruction drawnow, but it seems useless.
I hope someone of you guys knows how to solve my issue!
Best,
John_Arlecchino.
if self.plot_initialized == 0 % Initializing figure
self.figure_handle = figure; clf;
grid on;
colours = swarm.get_colors();
size_agents = repmat(30, swarm.nb_drones, 1);
pn = x_current(1, :);
pe = x_current(2, :);
pd = x_current(3, :);
self.scatter_handle = scatter3(pe, pn, -pd, size_agents, colours', 'filled');
for agent = 1:swarm.nb_drones
self.wake = zeros(10, 3, swarm.nb_drones);
for i = 1:10
self.wake(i, 1:3, agent) = x_current(1:3, agent);
end
end
xlabel('Y position [m]');
ylabel('X position [m]');
zlabel('Z position [m]');
xlim([-200 300])
ylim([-200 300])
axis square;
view(0,90);
grid on;
hold on;
self.plot_initialized = 1;
%----------------------------------------------------------
else
size_agents = repmat(30, swarm.nb_drones, 1);
colours = swarm.get_colors();
pn = x_current(1, :);
pe = x_current(2, :);
pd = x_current(3, :);
set(self.scatter_handle, 'Xdata', pe, 'Ydata', pn, ... % Here it is where points on plot disappear!
'Zdata', -pd, 'Marker', '.', 'SizeData', ...
size_agents, 'CData', colours');
xlabel('Y position [m]');
ylabel('X position [m]');
zlabel('Z position [m]');
axis square;
view(0,90);
grid on;
hold on;
colour_wake = 200*ones(10, 3);
for agent = 1:swarm.nb_drones
self.wake = circshift(self.wake, 1);
self.wake(1, :, agent) = x_current(:, agent);
self.lines_handle(agent) = scatter(...
self.wake(1:end, 2, agent), ...
self.wake(1:end, 1, agent), 4, colour_wake);
hold on;
drawnow;
end
end
2 Kommentare
Rik
am 27 Okt. 2019
Your setting hold on after you created a new plot with the scatter function. You also aren't using any explicit parent when creating your graphical elements. This is probably fine in the initialization phase (as the user probably wouldn't select another figure during that part), but especially in the second part of your code, this is required for a robust GUI design.
The drawnow function forces a graphics update (and the execution of any queued callbacks), so that can be helpful if you want to show the user something changing in a loop, but it does not actually create new graphical elements.
I hope this helps.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!