Ma · Mathematics

How to Plot x² + y² = z²

Published By the 9to5Science editorial team

At a glance

  1. 1. Read the equation

    Assume the equation is x² + y² = z²; it describes a surface in three-dimensional space.

  2. 2. Identify both branches

    Solving for z gives z = √(x² + y²) and z = −√(x² + y²), forming a double cone.

  3. 3. Choose a plotting range

    Restrict x and y to a finite interval so the plotted surface fits in the graph.

  4. 4. Plot both surfaces

    Use a 3D plotting tool to graph the positive and negative square-root branches.

Assuming the intended equation is x2+y2=z2x^2+y^2=z^2, its graph is a three-dimensional surface, not a single curve. It is a double cone with its tip at the origin and its axis along the zz-axis. You can plot it by expressing zz in terms of xx and yy and graphing both possible values.

Rewrite the equation as two surfaces

Taking square roots gives

z=x2+y2orz=−x2+y2.z=\sqrt{x^2+y^2}\quad\text{or}\quad z=-\sqrt{x^2+y^2}.

Both signs are required because the original equation contains z2z^2. The positive branch is the upper nappe of the cone, and the negative branch is the lower nappe. If the intended equation also includes the restriction z≥0z\geq 0, then plot only the positive branch.

The equation is symmetric in xx and yy. For any fixed value z=cz=c, the cross-section satisfies x2+y2=c2x^2+y^2=c^2, which is a circle of radius ∣c∣|c| in the horizontal plane. As ∣z∣|z| increases, these circles get larger, producing the cone shape.

Plot it in Python

This example uses NumPy to calculate the surface and Matplotlib to draw it. Install the packages first if needed with python -m pip install numpy matplotlib.

import numpy as np
import matplotlib.pyplot as plt

# Sample a square region in the x-y plane.
limit = 3
x = np.linspace(-limit, limit, 120)
y = np.linspace(-limit, limit, 120)
X, Y = np.meshgrid(x, y)
R = np.sqrt(X**2 + Y**2)

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

# Plot the upper and lower nappes.
ax.plot_surface(X, Y, R, cmap="viridis", alpha=0.85)
ax.plot_surface(X, Y, -R, cmap="viridis", alpha=0.85)

z_limit = np.sqrt(2) * limit
ax.set_xlim(-limit, limit)
ax.set_ylim(-limit, limit)
ax.set_zlim(-z_limit, z_limit)
ax.set_box_aspect((2 * limit, 2 * limit, 2 * z_limit))
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
ax.set_title("x² + y² = z²")

plt.show()

The grid is limited to −3≤x,y≤3-3\leq x,y\leq 3, so the displayed cone is only a finite portion of an otherwise unbounded surface. R computes x2+y2\sqrt{x^2+y^2} at every grid point; plotting R and -R supplies the two branches. The box aspect ratio matches the axis ranges so that equal coordinate distances are shown at comparable scales.

Check the plot with points and slices

A point belongs to the surface exactly when its coordinates satisfy the equation. For example, (3,4,5)(3,4,5) lies on it because

32+42=9+16=25=52.3^2+4^2=9+16=25=5^2.

The point (3,4,−5)(3,4,-5) lies on it too, since (−5)2=25(-5)^2=25. By contrast, (3,4,4)(3,4,4) does not: its left side is 2525, while its right side is 1616.

You can also verify the shape using horizontal slices. At z=2z=2, the cross-section is x2+y2=4x^2+y^2=4, a circle of radius 22. At z=−2z=-2, it is the same circle. At z=0z=0, the only point is the origin.

Common plotting mistakes

  • Plotting only one branch: Graphing z=x2+y2z=\sqrt{x^2+y^2} shows only the upper cone. The equation with z2z^2 includes the lower cone as well.
  • Treating the equation as a 2D graph: There are three variables, so the full graph is a surface in 3D. A 2D plot can show a cross-section, such as the circle at a fixed zz value.
  • Using an infinite plotting range: A computer plot needs finite coordinate limits. Changing the grid range changes how much of the cone is visible, not the equation itself.
  • Ignoring the equation’s signs or operators: If the intended expression was not x2+y2=z2x^2+y^2=z^2, its graph may be different. For instance, adding z2z^2 to the left side and setting the result equal to a constant gives a sphere, not a cone.

References

  1. Matplotlib: 3D surface (plot_surface)
  2. NumPy documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.