Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

How to Set xlim and zlim in a Matplotlib 3D Scatter Plot

Use set_xlim and set_zlim on the 3D axes object to control the visible x and z ranges of a Matplotlib scatter plot.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set the limits on the 3D axes object that contains the scatter plot: call ax.set_xlim(x_min, x_max) and ax.set_zlim(z_min, z_max). These bounds are in data coordinates and control the visible axis ranges.

Set both limits on the 3D axes

Create a 3D axes, draw the scatter plot on it, and use that same ax object to set the x and z limits:

As an Amazon Associate I earn from qualifying purchases.

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.scatter(x, y, z)

ax.set_xlim(x_min, x_max)
ax.set_zlim(z_min, z_max)

This follows Matplotlib’s official 3D scatterplot example, which creates an axes with projection="3d" and plots through its axes methods. For 3D operations, use the explicit axes object: the mplot3d documentation notes that pyplot functions cannot add content to 3D plots because their signatures are strictly 2D. See the mplot3d toolkit documentation.

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

Choose the x and z bounds

set_xlim and set_zlim set view bounds in the data’s coordinate system. For example, ax.set_zlim(0, 10) makes the displayed z range run from 0 to 10. The z method accepts separate endpoints or one two-item pair:

ax.set_zlim(0, 10)
# Equivalent:
ax.set_zlim((0, 10))

The Axes3D.set_zlim API reference documents both forms. You can leave one endpoint unchanged by passing None for it, or use the named argument for the endpoint you want to set:

ax.set_zlim(bottom=0)  # keep the current upper limit
ax.set_zlim(top=10)    # keep the current lower limit

Reversing the endpoints reverses the axis direction; for example, ax.set_zlim(5000, 0) displays values descending from bottom to top, which can be useful for depth-oriented data.

Use the combined property-setting form

If you are setting several axes properties together, the compact form ax.set can set x and z limits in one call:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ax.set(xlim=(x_min, x_max), zlim=(z_min, z_max))

Matplotlib uses this form in its official 3D view-limit clipping example. Separate calls to set_xlim and set_zlim are equally suitable when you want each change to be explicit.

Limits change the view, not the data

Setting limits changes the plotted view bounds; it does not edit or delete values in your original x, y, or z arrays. This is distinct from optional 3D clipping. In the clipping example, Matplotlib shows that enabling axlim_clip hides a line segment when one of its vertices lies outside the view limits. Use clipping when you need that behavior; do not treat axis limits alone as a data-filtering operation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the installed Matplotlib version if behavior differs

The cited stable documentation identifies Matplotlib versions 3.11.0 through 3.11.2. If an API signature or behavior differs in your environment, check the version installed there and consult documentation for that version.

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.

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

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.