Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python : 2D perspective projection of a 3D surface plot

I am making a 3D surface plot using matplotlib (python). I want to visualize the shadow (2D perspective projection) of the 3D surface on xy xz and yz surface.

In matlab, SHADOWPLOT does the needed work. Does anyone know if Python has something similar that can be used for the same?

like image 428
Panchi Avatar asked Jan 12 '23 01:01

Panchi


1 Answers

Example from {here}:

"""
.. versionadded:: 1.1.0
   This demo depends on new features added to contourf3d.
"""

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contourf(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)

plt.show()

and result:

enter image description here

like image 146
Developer Avatar answered Jan 28 '23 23:01

Developer