PYTHON画三维图

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

#bbb=[1 if (i <=0.5 or i >=1.5) else 0 for i in D

def fun(x, y):
value= x**2+y**2


return value

fig1 = plt.figure()
ax = Axes3D(fig1)
X, Y = np.mgrid[-4:4:40j, -4:4:40j]
Z1 = fun(X, Y)
numsize=len(Z1)
Z=Z1
for i in range(40):
for j in range(40):
if (Z1[i][j]<0.5 ):
Z[i][j]=1
elif (Z1[i][j]>11):
Z[i][j]=1
else:
Z[i][j]=0
# for i in range(len(Z1)):
# if lis[i] in str:
# lis[i]='-'
# print(lis)



# Z=[1 if (i <=10 or i >=20) else 0 for i in Z1]

# plt.title("This is main title")
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.cm.coolwarm, alpha=0.5)
ax.set_xlabel('u', color='b')
ax.set_ylabel('v', color='r')
ax.set_zlabel('H(u,v)', color='g')
plt.show()
posted @ 2019-12-29 21:15  水木清扬  阅读(1245)  评论(0编辑  收藏  举报