3D graphics using maplot3d from matplotlib-

I need to build data that is in the following format:

x = range(6)
y = range(11)

and z depends on x , y

For each value of x, there must be a continuous curve showing the change in z wrt y and the curves for different values ​​of x should be disabled

I use mplot3d, and it’s not very clear how to build switchable curves.

This is what seems like using graphs. enter image description here

+5
source share
1 answer

You can overlay multiple graphs with Axes3D.plot :

import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d
import numpy as np

x = np.arange(6)
y = np.linspace(0, 11, 50)
z = x[:, np.newaxis] + y**2

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection = '3d')
for xval, zrow in zip(x, z):
    ax.plot(xval*np.ones_like(y), y, zrow, color = 'black')
plt.show()

enter image description here

+6
source

All Articles