4

I would like to draw multiple independent lines in a 3D plot in Python. It looks like: enter image description here.

I am new at Python. Would you help me?

Serenity
  • 35,289
  • 20
  • 120
  • 115
huangteng1220
  • 41
  • 1
  • 2
  • Does this answer your question? [How to 3D plot function of 2 variables in python?](https://stackoverflow.com/questions/51765184/how-to-3d-plot-function-of-2-variables-in-python) – Trenton McKinney Sep 18 '20 at 16:33

1 Answers1

2

You have to work with matplotlib library (mplot3d package).

Here is a little example of 3dr plot with lines:

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

# make 3d axes
fig = plt.figure()
ax = fig.gca(projection='3d')

# test data
x = np.arange(-1., 1., .1)
y = np.arange(-1., 1., .1)
z1 = x + y
z2 = x * x
z3 = -y * y

# plot test data
ax.plot(x, y, z1)
ax.plot(x, y, z2)
ax.plot(x, y, z3)

# make labels
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Serenity
  • 35,289
  • 20
  • 120
  • 115