簡體   English   中英

3d plot in Python - 條件 function 中缺少最大值

[英]3d plot in Python - max value is missing with conditional function

我正在嘗試獲取 3d plot,其中我的 function 是有條件的。 但是,在這種情況下,最大值 - 1 丟失了。 如果我有一個沒有條件的 function,則 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM