统计机器学习-三维绘图

用python绘制三维函数图像:

Z = X 2 + Y 2 Z = X^2 + Y^2 Z=X2+Y2

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')

x = np.arange(-3, 3, 0.1)
y = np.arange(-3, 3, 0.1)
X,Y = np.meshgrid(x,y)  
Z = X**2+Y**2
ax.plot_surface(X, Y, Z, alpha=0.3, cmap= plt.cm.winter)
ax.set_xlabel("X")
ax.set_xlim(-3,3)
ax.set_ylabel("Y")
ax.set_ylim(-3,3)
ax.set_zlabel("Z")
plt.title("Z = X^2 + Y^2")
plt.show()

绘制效果:
统计机器学习-三维绘图_第1张图片

你可能感兴趣的:(python,latex)