October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Create a Matplotlib 3D Scatter Animation in Python

Use a 3D Axes, a scatter collection, and a FuncAnimation callback to animate points in Python. Includes a working example, export options, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To animate a 3D scatter plot in Matplotlib, create a 3D Axes with projection="3d", make a scatter collection, and update that collection from a FuncAnimation callback. Keep the animation object in a variable so it continues running. The example below shows points moving along a 3D path and includes display and export options.

Build and display a 3D scatter animation

Matplotlib defines an animation as a sequence of frames, each corresponding to a plot on a Figure. For a 3D scatter, the key detail is that each point’s x, y, and z coordinates must stay aligned, and the callback must update the existing scatter artist rather than use a 2D pyplot plotting call.

Complete example

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

# Create one path through 3D space.
n_points = 40
t = np.linspace(0, 4 * np.pi, n_points)
x = np.cos(t)
y = np.sin(t)
z = np.linspace(-1, 1, n_points)

fig = plt.figure()
ax = fig.add_subplot(projection="3d")

# Fix the view bounds so the plot does not rescale as points move.
ax.set(xlim=(-1.2, 1.2), ylim=(-1.2, 1.2), zlim=(-1.2, 1.2))
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")

# Start with one point. A 3D scatter returns a Path3DCollection.
points = ax.scatter(x[:1], y[:1], z[:1])

def update(frame):
    # Update the collection with all points up to this frame.
    points._offsets3d = (x[:frame + 1], y[:frame + 1], z[:frame + 1])
    return (points,)

ani = FuncAnimation(
    fig,
    update,
    frames=n_points,
    interval=50,
    blit=False,
)

plt.show()

The _offsets3d assignment updates the 3D coordinates on the scatter collection. It is a private attribute, so check it against the Matplotlib version you use; the public Axes3D.scatter method creates the collection but does not itself supply a documented public setter for changing its 3D offsets. The official 3D animation gallery demonstrates the callback pattern with moving lines, not a scatter-specific setter.

What the callback is doing

  • frames=n_points supplies frame indices from zero through the last point.
  • update(frame) receives the current frame and updates the same collection with coordinate slices of equal length.
  • Returning the changed artist, here as a one-item tuple, identifies what the callback updated.
  • ani holds a reference to the animation. If the object is not retained, it can be garbage collected and its timer may stop.

Adapt the example to your data

Keep coordinates paired

For every point, x[i], y[i], and z[i] must describe that same point. They should have matching lengths. If each frame represents a new cloud rather than a growing path, store one x, y, and z array per frame and assign the three arrays for the current frame in the callback.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Bambu Lab P1S Combo, P1S 3D Printer and AMS, Multi-Color 3D Printing
  • Up to 16 Colors: Bring your designs to life with vibrant multi-color/multi-material printing capabilities, perfect for showcasing your creativity. Note: Connecting Bambu Lab AMS is required.
  • 500mm/s and 20000 mm/s² Acceleration True High Speed: Don't wait around for your masterpieces. Lightning-fast printing speed lets you focus on creating, not waiting.
  • Enclosed Design: Fully enclosed body improves print performance for advanced filaments. Automatic Bed Leveling: Say hello to high-quality, successful prints. Auto bed leveling makes 3D printing such an easy thing.
  • Set Up in 15 Minutes: Spend more time printing and less time setting up. User-friendly design ensures a hassle-free assembly experience for all skill levels.
  • Supported Filament: Ideal: PLA, PETG, TPU, PVA, PET ABS, ASA; Capable : PA, PC; Not Recommended: Carbon/Glass Fiber Reinforced Polymer.

Choose the frame behavior

The example reveals more of one path on each frame. To show a fixed-size moving cloud instead, choose a moving window of indices in update, or provide frame-specific coordinate arrays. In either case, update the existing collection rather than create another scatter collection on every callback; repeatedly creating artists can clutter the axes and make the animation harder to manage.

Set bounds intentionally

For moving data, set x, y, and z limits based on the full range you expect to display. Otherwise, automatic scaling can make the apparent camera framing change as points move. If the data range is unknown, calculate bounds from the whole sequence before starting the animation, with a small margin so points near the extremes are not clipped.

Rank #2
Sale
FLASHFORGE Adventurer 5M 3D Printer with Fully Auto Leveling, Max 600mm/s High Speed Printing, 280°C Direct Extruder with 3S Detachable Nozzle, CoreXY All Metal Structure, Print Size 220x220x220mm
  • One-Click Automatic Printing: Experience hassle-free 3D printing with the Adventurer 5M Series. Enjoy automatic bed leveling for flawless first layers, ensuring consistent adhesion and saving time with no manual adjustments required.
  • 12X Ultra Fast Printing: Featuring a CoreXY structure with 600mm/s travel speed and 20000mm/s² acceleration, the AD5M maximizes efficiency, reduces production cycles, and ensures high precision, making it ideal for rapid prototyping and mass production.
  • Smart and Efficient Design: Quick 3-second nozzle changes, a high-flow 32mm³/s nozzle, and fast 35-second warm-up to 200°C deliver stable high-speed printing. Its dual-sided PEI platform and versatile options provide easy removal and adaptability for various creative projects.
  • Superior Print Quality & Adaptability: Combines a 280°C direct drive extruder with dual-fan cooling and vibration compensation. Includes a standard 0.4mm nozzle and accepts optional sizes from 0.25mm to 0.8mm to fit various printing needs.
  • Real-Time App Monitoring: Monitor print progress, adjust settings, and receive instant status alerts remotely with the Flash Studio. Smart mobile control ensures a seamless, effortless printing experience anytime, anywhere.

Choose how to view or export it

Interactive display

plt.show() displays the figure using the active Matplotlib backend. Interactive backends can support rotating and zooming an mplot3d scene. If the animation appears frozen or the window does not behave interactively, check which backend your environment is using; notebook, script, and headless environments may behave differently.

Save an animation or embed it

Matplotlib’s Animation API provides Animation.save, Animation.to_html5_video, and Animation.to_jshtml. For example, to create an HTML representation in a notebook, evaluate ani.to_jshtml(); to save a file, call ani.save("scatter.mp4") with a supported writer and codec available in your environment. Writer availability and output support depend on the local installation, so verify the chosen route rather than assuming a particular format works everywhere.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Bambu Lab P1S 3D Printer, Ready-to-Use FDM 3D Printer
  • Up to 16 Colors: Bring your designs to life with vibrant multi-color/multi-material printing capabilities, perfect for showcasing your creativity. Note: Connecting Bambu Lab AMS is required.
  • 500mm/s and 20000 mm/s² Acceleration True High Speed: Don't wait around for your masterpieces. Lightning-fast printing speed lets you focus on creating, not waiting.
  • Enclosed Design: Fully enclosed body improves print performance for advanced filaments. Automatic Bed Leveling: Say hello to high-quality, successful prints. Auto bed leveling makes 3D printing such an easy thing.
  • Set Up in 15 Minutes: Spend more time printing and less time setting up. User-friendly design ensures a hassle-free assembly experience for all skill levels.
  • Supported Filament: Ideal: PLA, PETG, TPU, PVA, PET ABS, ASA; Capable : PA, PC; Not Recommended: Carbon/Glass Fiber Reinforced Polymer.

Troubleshoot common problems

  • The animation stops or never starts: keep a live reference such as ani for as long as the figure is open, and make sure the backend supports interactive animation if you expect a live window.
  • Points move to unexpected positions: check that x, y, and z values are paired by index and that the three arrays supplied for each frame have matching lengths.
  • The scale jumps: set fixed axis limits using the full data range instead of relying on autoscaling as the coordinates change.
  • Saving fails: check that the requested writer and codec are installed and available for your Matplotlib environment, or choose one of the documented HTML conversion methods where suitable.
  • Blitting causes rendering issues: begin with blit=False. Blitting is a performance technique, but support and benefit depend on the backend and artist behavior; the animation API also notes that blitted artists appear above other artists regardless of z-order.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When Matplotlib is the right tool

Matplotlib’s mplot3d toolkit adds simple 3D scatter, surface, line, and mesh plotting by projecting a 3D scene onto a 2D Axes. It is convenient when your animation belongs in an existing Python and Matplotlib workflow, but Matplotlib describes mplot3d as neither the fastest nor the most feature-complete 3D library. For simple animated data exploration or figures, it can be a lightweight fit; for demanding interactive rendering or more advanced 3D features, consider a dedicated 3D visualization library. The current stable documentation surfaced for these APIs is labeled Matplotlib 3.11.2.

Best Value
FLASHFORGE Adventurer 5M Pro 3D Printer with 1 Click Auto Printing System
  • 600mm/s Speed & CoreXY Structure — Powered by an all-metal CoreXY frame and 20,000mm/s² acceleration, Adventurer 5M Pro reaches speeds up to 600mm/s. Integrated vibration compensation algorithms eliminate ghosting and ringing for smooth, high-precision surface finishes.
  • 3-Second Quick-Swap Nozzle & Auto Leveling — Features a tool-free, quick-release nozzle mechanism for effortless 3-second replacements across multiple sizes (0.25/0.4/0.6/0.8mm). One-click full auto-leveling ensures precise bed calibration and a perfect first layer every time.
  • Dual Filtration System & Quiet Enclosure — Built with an integrated dual filtration system and a fully enclosed chamber to ensure a clean printing environment and thermal stability. Powered by low-noise motion control, it operates quietly under 50dB for seamless home, office, or classroom use.
  • 280°C High-Temp Extruder & Broad Material Compatibility — With a 280°C max nozzle temperature and a 110°C heated bed, it reliably prints engineering materials like ABS, ASA, and PETG-CF, as well as standard PLA and PETG.
  • Smart Camera & Mobile Control — Features a built-in camera for real-time monitoring and time-lapse video creation. Monitor progress, adjust settings, and receive instant status alerts via Flash Studio. Integrated with filament detection, power loss recovery, and a 4.3-inch touchscreen for effortless operation.
Rank #4
Bambu Lab P2S Combo, P2S 3D Printer & AMS 2 Pro, Multi-Color 3D Printing
  • High-Speed Precision: The Bambu Lab P2S 3D printer prints up to 600 mm/s while maintaining exceptional accuracy. With the PMSM Servo Extruder and Active Flowrate Compensation, every layer of your printed object stays sharp and smooth, delivering flawless corners and consistent results.
  • Ready to Print in 15 Minutes: Set up your P2S FDM 3D printer and start printing in just 15 minutes. With AI failure detection, quick-swap nozzles, and automatic calibration, this 3D printer makes professional-grade 3D printing effortless, even for beginners.
  • Effortless Multi-Color Printing: The AMS 2 Pro enables seamless multi-color/multi-material 3D printing. It features built-in filament drying at up to 65 °C, keeping every spool ready for flawless prints. (Note: The P2S 3D printer does not support multi-color printing; Combo version required.)
  • Smart Airflow for Any Filament: The Adaptive Airflow System automatically balances cooling and heat retention—keeping overhangs crisp with cool air, or maintaining a 50 °C chamber for engineering-grade materials. A carbon filter ensures clean, safe air while you print.
  • Limitless Creativity, Seamless Workflow: Explore over one million 3D models on MakerWorld and bring them to life with a smooth, unified workflow using Bambu Studio, Bambu Handy, and your FDM 3D printer, from design to finished print.

Official references

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.