示例程序如下:
import matplotlib
.pyplot as plt
from mpl_toolkits
.mplot3d import Axes3D
import numpy as np
def
fun(x
, y
):
return x
**2+y
**2
fig1
= plt
.figure()
ax
= Axes3D(fig1
)
X
, Y
= np
.mgrid
[-2:2:40j
, -2:2:40j
]
Z
= fun(X
, Y
)
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('x label', color
='b')
ax
.set_ylabel('y label', color
='r')
ax
.set_zlabel('z label', color
='g')
plt
.show()