matplotlib

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-1, 1, num=10)#-1到1 10个元素
y = 3 * x + 2
plt.plot(x, y) #画图
plt.show()  #显示

 

x1 = np.linspace(1, 10) #默认生成元素为50的等差数列
x2 = np.linspace(1, 10, num=5, retstep = True)
print(x1)
print(x2)
print("length of x1 is %d" %len(x1))
print("length of x2 is %d" %len(x2))
[ 1.          1.18367347  1.36734694  1.55102041  1.73469388  1.91836735
  2.10204082  2.28571429  2.46938776  2.65306122  2.83673469  3.02040816
  3.20408163  3.3877551   3.57142857  3.75510204  3.93877551  4.12244898
  4.30612245  4.48979592  4.67346939  4.85714286  5.04081633  5.2244898
  5.40816327  5.59183673  5.7755102   5.95918367  6.14285714  6.32653061
  6.51020408  6.69387755  6.87755102  7.06122449  7.24489796  7.42857143
  7.6122449   7.79591837  7.97959184  8.16326531  8.34693878  8.53061224
  8.71428571  8.89795918  9.08163265  9.26530612  9.44897959  9.63265306
  9.81632653 10.        ]
(array([ 1.  ,  3.25,  5.5 ,  7.75, 10.  ]), 2.25)
length of x1 is 50
length of x2 is 2

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-5,5,num=100)
y1 = 2*x + 1
y2 = x**2

plt.figure(num=1,figsize=(16,9)) #第一个窗口
plt.plot(x,y1)

plt.figure(num=2)#第二个窗口
plt.plot(x,y2)

plt.figure(num=3)
plt.plot(x,y1)
plt.plot(x,y2,color='red',linewidth=1.0,linestyle='--')
plt.show()

 

posted @ 2018-10-04 13:19  crazybird123  阅读(102)  评论(0编辑  收藏  举报