I want to show a separation between my 3d plot data. Like dividing them between top and bottom of Z = 100
surface.
This is my code:
# x, y, t are lists of points that shows (x,y) coordinate of an object at time t
cor_x = np.poly1d(np.polyfit(t, x, 5))
cor_y = np.poly1d(np.polyfit(t, y, 5))
ax = plt.axes(projection="3d")
ax.plot3D(cor_x(t), cor_y(t), t)
plt.show()
All I want is a transparent z = 100 surface.
If you want to plot a surface use ax.plot_surface(X, Y, Z)
. Where X,Y are the 2d grid created with np.meshgrid
and Z is the data on the same grid. You can make the z=100 surface by taking your data and multiplying by zero and adding 100.
You can use alpha
to change the transparency. Note that the more transparent the harder to see which may not be the best approach to separate your data.
Here is an example.
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
def f(x, y):
return x**2 + y**2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = y = np.arange(-10.0, 10.0, .1)
X, Y = np.meshgrid(x, y)
Z = f(X,Y)
ax.plot_surface(X, Y, Z,color='gray',alpha=.8)
#To plot the surface at 100, use your same grid but make all your numbers zero
Z2 = Z*0.+100
ax.plot_surface(X, Y, Z2,color='r',alpha=.3) #plot the surface
plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.