Python中的3d绘图-条件函数缺少最大值



我正在尝试获得一个3d图,其中我的函数是有条件的。但是,在这种情况下,缺少最大值-1。如果我有一个没有条件的函数,1在图上:


import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
x=np.linspace(0,1,100)
y = np.linspace(0,1,100)

def I_LK(x,y):
v=1-x+y
return np.where(v<=1, v, 1)
#return 1-x+x*y # here there is no problem

X,Y = np.meshgrid(x,y)
Z=I_LK(X,Y)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.contour3D(X, Y, Z, 100, cmap='viridis')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_zlim(0,1.1)

我怎样才能获得价值;1〃;在我的图表上?

如果有人会找它,正确的方法如下:


import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
x=np.linspace(0,1,100)
y = np.linspace(0,1,100)

def I_LK(x,y):
v=1-x+y
return np.where(v<=1, v, 1)
#return 1-x+x*y # here there is no problem

X,Y = np.meshgrid(x,y)
Z=I_LK(X,Y)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, Z, cmap='viridis')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_zlim(0,1.1)

plot_surface而非contour3D

最新更新