numpy.meshgrid()

numpy提供的numpy.meshgrid()函数可以让我们快速生成坐标矩阵X,Y

语法:X,Y = numpy.meshgrid(x, y)
输入:x,y,就是网格点的横纵坐标列向量(非矩阵)
输出:X,Y,就是坐标矩阵。

import numpy as np
import matplotlib.pyplot as plt
x = np.array([0, 1, 2])
y = np.array([0, 1])

X, Y = np.meshgrid(x, y)
print(X)
print(Y)

plt.plot(X, Y,
         color='red',  # 全部点设置为红色
         marker='.',  # 点的形状为圆点
         linestyle='')  # 线型为空,也即点与点之间不用线连接
plt.grid(True)
plt.show()

输出:

X = [[0 1 2] [0 1 2]]

Y = [[0 0 0] [1 1 1]]

 

参考文献:

【1】numpy.meshgrid()理解

posted @ 2019-03-02 21:13  nxf_rabbit75  阅读(316)  评论(0)    收藏  举报