Animated 3D Scatter Plot (2024)

54 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Fabio Taccaliti am 20 Apr. 2022

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot

Kommentiert: Star Strider am 20 Apr. 2022

Akzeptierte Antwort: Star Strider

In MATLAB Online öffnen

Hello,

I would like to create an animated 3D scatter plot that is plotting the points included in the sub-array of a cell DD (102x1 cell), each sub-array is a 29x4 (where the last three column are the 3 coordinates (x,y.z)). Here below an example of my cell and sub-array.

M = [[0;0.2;0.2;0.4;0.6;0.6;0.6],rand(7,3)]

D = diff(find([1;diff(M(:,1));1]));

DD = mat2cell(M,D,4);

DD{:}

The animated scatter should display together each subarray points and then in a subsequent time step the next subarray points.

Here below the code that alreay plot all the points together.

figure(1)

for i = 1:numel(DD)

hold on; grid on; grid minor; axis equal;

set(gcf, 'Color', 'White');

set(gca, 'Fontsize', 12);

set(gca, 'ZDir','reverse')

scatter3(DD{i}(:,2),DD{i}(:,3),DD{i}(:,4))

view(3)

xlabel('x [mm]')

ylabel('y [mm]')

zlabel('z [mm]')

end

Thanks in advance

0 Kommentare

-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Star Strider am 20 Apr. 2022

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#answer_946555

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#answer_946555

In MATLAB Online öffnen

Try this slightly augmented version —

figure(1)

hold on

grid minor

axis([0 2 0 2 0 2])

for i = 1:numel(DD)

view(3)

set(gcf, 'Color', 'White');

set(gca, 'ZDir','reverse')

scatter3(DD{i}(:,2),DD{i}(:,3),DD{i}(:,4))

grid on

axis([0 2 0 2 0 2])

drawnow

pause(0.25)

xlabel('x [mm]')

ylabel('y [mm]')

zlabel('z [mm]')

end

hold off

It fixes the axis limits and adds drawnow and pause to create the animation.

Experiment to get the desired results.

.

6 Kommentare

4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden

Fabio Taccaliti am 20 Apr. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2112910

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2112910

Thanks a lot for the answer, the problem is that I would like to have axis equal on my plot but then in order to have it I need the hold on command and this involves that I will plot all the sub-array on top of each other without 'cleaning' the plot each time and plot just one sub-array each time with the 0.25s pause.

Do you know how can I fix it?

Star Strider am 20 Apr. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113070

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113070

In MATLAB Online öffnen

My pleasure.

When I run the code I posted, the plot does not ‘clear’. All the points are plotted and remain visible, with new ones appearing in each interation of the loop.

Add the axis equal call after the first axis call —

figure(1)

hold on

grid minor

axis([0 2 0 2 0 2])

axis equal

for i = 1:numel(DD)

view(3)

set(gcf, 'Color', 'White');

set(gca, 'Fontsize', 12);

set(gca, 'ZDir','reverse')

scatter3(DD{i}(:,2),DD{i}(:,3),DD{i}(:,4))

grid on

axis([0 2 0 2 0 2])

drawnow

pause(0.25)

xlabel('x [mm]')

ylabel('y [mm]')

zlabel('z [mm]')

end

hold off

Both of the axis calls are necessary.

.

Fabio Taccaliti am 20 Apr. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113505

Sorry maybe from what I wrote was not clear.

I would like that the plot 'clear' each iteration without showing the one from the previous.

Now from this code the axis remain equal that is perfect, but still all the points are plotted and remain visible (which I would like to avoid ) and show just the point for each iteration.

I tried several combination of hold on and hold off but still nothing.

Star Strider am 20 Apr. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113605

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113605

In MATLAB Online öffnen

To do that, remove the hold calls —

figure(1)

grid minor

axis([0 2 0 2 0 2])

axis equal

for i = 1:numel(DD)

view(3)

set(gcf, 'Color', 'White');

set(gca, 'Fontsize', 12);

set(gca, 'ZDir','reverse')

scatter3(DD{i}(:,2),DD{i}(:,3),DD{i}(:,4), 'filled')

grid on

axis([0 2 0 2 0 2])

drawnow

pause(0.25)

xlabel('x [mm]')

ylabel('y [mm]')

zlabel('z [mm]')

end

.

Fabio Taccaliti am 20 Apr. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113895

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113895

Thanks a lot, now it works :)

Star Strider am 20 Apr. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113955

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113955

As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Steven Lord am 20 Apr. 2022

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#answer_946860

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#answer_946860

In MATLAB Online öffnen

Rather than recreating the scatter plot each time, I'd apply the first of the techniques listed on the Animation Techniques documentation page. If I ran this in MATLAB Answers you wouldn't see the animation, but if you run it in MATLAB you can.

% Sample data

theta = 0:15:360;

x = cosd(theta);

y = sind(theta);

% Create the initial "frame" of the animation

h = scatter(x, y, 'o');

% Control the axes so at its "widest" the whole circle still fits

axis([-5 5 -5 5])

% Make it look circular

axis equal

% At each frame, push each point outward (or pull it inwards)

for r = repmat([1:5 4:-1:2], 1, 10)

% Update the existing object's properties rather than creating a new one

h.XData = r*x;

h.YData = r*y;

% Let you see the animation

pause(0.1)

end

In the "real" animation you might want to use one of the options for drawnow instead of pause.

1 Kommentar

-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Fabio Taccaliti am 20 Apr. 2022

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113900

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/1700565-animated-3d-scatter-plot#comment_2113900

Thanks Steven, I'll have a better look into this :)

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABGraphics2-D and 3-D PlotsAnimation

Mehr zu Animation finden Sie in Help Center und File Exchange

Tags

  • plot
  • 3d

Produkte

  • MATLAB

Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Animated 3D Scatter Plot (11)

Animated 3D Scatter Plot (12)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Kontakt zu Ihrer lokalen Niederlassung

Animated 3D Scatter Plot (2024)
Top Articles
Latest Posts
Article information

Author: Amb. Frankie Simonis

Last Updated:

Views: 6577

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Amb. Frankie Simonis

Birthday: 1998-02-19

Address: 64841 Delmar Isle, North Wiley, OR 74073

Phone: +17844167847676

Job: Forward IT Agent

Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.