python画三维图
程序员文章站
2022-07-13 09:21:23
...
个人做笔记使用,不用每次画图的时候都去找代码了。
三维
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import math
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
w=[i+1 for i in range(100)]
q=[i+1 for i in range(100)]
W,Q=np.meshgrid(w,q)
Z=np.zeros(Q.shape)
def getZ(w,q):
sumZ=0
for i in range(q):
i=i+1
if i<=w:
sumZ+=math.factorial(w)/math.factorial(w-i)/math.factorial(i)
return sumZ
for i in range(Z.shape[0]):
for j in range(Z.shape[1]):
Z[i,j]=getZ(W[i,j],Q[i,j])
ax.set_xlabel('W Label')
ax.set_ylabel('Q Label')
ax.set_zlabel('Z Label')
surf = ax.plot_surface(W, Q, Z,cmap=cm.coolwarm,
linewidth=0, antialiased=False)