matplotlib--> pyplot&np.arange()函数的简单用法!

 1 import numpy as np
 2 import matplotlib.pyplot as plt
 3 
 4 # Compute the x and y coordinates for points on sine and cosine curves
 5 x = np.arange(0, 3 * np.pi, 0.1)
 6 y_sin = np.sin(x)
 7 y_cos = np.cos(x)
 8 
 9 # Plot the points using matplotlib
10 plt.plot(x, y_sin)
11 plt.plot(x, y_cos)
12 plt.xlabel('x axis label')
13 plt.ylabel('y axis label')
14 plt.title('Sine and Cosine')
15 plt.legend(['Sine', 'Cosine'])
16 plt.show()

np.arange()用法

返回值: np.arange()函数返回一个有终点和起点的固定步长的排列。

参数:

1)一个参数时,参数值为终点,起点取默认值0,步长取默认值1。

2)两个参数时,第一个参数为起点,第二个参数为终点,步长取默认值1。

3)三个参数时,第一个参数为起点,第二个参数为终点,第三个参数为步长。其中步长支持小数。

例子:

a = np.arange(3) # 默认起点0,步长为1 输出:[0 1 2]

a = np.arange(3,6) # 默认步长为1 输出:[3 4 5]

a = np.arange(0, 3, 0.1) # 输出:[ 0.  0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9  1.  1.1  1.2  1.3  1.4 1.5  1.6  1.7  1.8  1.9  2.  2.1  2.2  2.3  2.4  2.5  2.6  2.7  2.8  2.9]

To see I can not see, to know I do not know.
原文地址:https://www.cnblogs.com/aluomengmengda/p/14192681.html