numpy中meshgrid的使用
2019-06-12 17:32
1266 查看
meshgrid的适用于生成网格型数据,可以接受两个一维数组生成两个二维矩阵,对应两个数组中所有的(x,y)对
例子
x = np.arange(1,4) x Out[13]: array([1, 2, 3]) y = np.arange(5,10) x Out[15]: array([1, 2, 3]) y Out[16]: array([5, 6, 7, 8, 9]) z1, z2 = np.meshgrid(x, y) z1 Out[21]: array([[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]) z2 Out[22]: array([[5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8], [9, 9, 9]]) z1.shape Out[< 4000 span class="token number">23]: (5, 3)
小结:meshgrid后生成的数组shape: (y.size, x.size),第一个数组每行都是x,第二个数组每列都是y
绘制3维图
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # 绘制散点图 x1 = np.arange(-4, 4, 0.25) x2 = np.arange(-4, 4, 0.25) x, y = np.meshgrid(x1, x2) r = np.sqrt(x ** 2 + y ** 2) z = np.sin(r) fig = plt.figure() ax = Axes3D(fig) ax.scatter(x, y, z) # 添加坐标轴(顺序是x, y, z) ax.set_xlabel('x', fontdict={'size': 10, 'color': 'red'}) ax.set_ylabel('y', fontdict={'size': 10, 'color': 'green'}) ax.set_zlabel('z', fontdict={'size': 10, 'color': 'blue'}) plt.show()
图像如下
相关文章推荐
- numpy中meshgrid使用
- numpy中meshgrid的使用
- numpy中meshgrid的使用
- android之对话框的使用
- 使用JavaScript的XMLHttpRequest发送POST、GET请求以及接收返回值
- JAVA Spring 使用fusionCharts的setDataXML方法
- Linux netstat命令详解和使用例子(显示各种网络相关信息)
- 使用VB编写纯ASP程序
- [转]Oracle DB 使用连接显示多个表中的数据
- CCLOG的使用
- 使用 CSS3 实现 3D 图片滑块效果【附源码下载】
- Selenium的安装和使用介绍
- Linux下gdb的安装及使用入门
- OpenCV学习笔记——使用OpenCV访问图像数据
- 【RPi树莓派使用指南】GPIO驱动方法
- 火狐浏览器中页面使用a标签提交后台执行两次,组件导致
- 使用XSD
- 在Xcode中使用Git进行源码版本控制
- 使用异或交换数据值的原理
- 模拟页面跳转,使用代理反向传值