import numpy as np
#meshgrid 转换成坐标的形式
x = np.arange(-5, 5, 1)
y = np.arange(-5, 5, 1)
xx, yy = np.meshgrid(x, y, sparse=True) # 为一维的矩阵
xx1, yy1 = np.meshgrid(x, y ) # 转换成二维的矩阵坐标
'''
xx1
[[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]
[-5 -4 -3 -2 -1 0 1 2 3 4]]
yy1
[[-5 -5 -5 -5 -5 -5 -5 -5 -5 -5]
[-4 -4 -4 -4 -4 -4 -4 -4 -4 -4]
[-3 -3 -3 -3 -3 -3 -3 -3 -3 -3]
[-2 -2 -2 -2 -2 -2 -2 -2 -2 -2]
[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
[ 0 0 0 0 0 0 0 0 0 0]
[ 1 1 1 1 1 1 1 1 1 1]
[ 2 2 2 2 2 2 2 2 2 2]
[ 3 3 3 3 3 3 3 3 3 3]
[ 4 4 4 4 4 4 4 4 4 4]]
'''
# 这样的目的画成一个
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = np.meshgrid(x, y ) # 转换成二维的矩阵坐标
fig = plt.figure(1, figsize=(12, 8))
zz = (xx**2 + yy**2)
ax = fig.add_subplot(2, 2, 1, projection='3d')
ax.set_top_view()
ax.plot_surface(xx, yy, zz, rstride=1, cstride=1, cmap='rainbow')
plt.show()
python之meshgrid的使用
原创
©著作权归作者所有:来自51CTO博客作者待???的一天的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:网络npy权值文件的使用
下一篇:python中的广播
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章