matplotlib
Matplotlib 是 Python 的绘图库。 它可与 NumPy 一起使用,提供了一种有效的 MatLab 开源替代方案。
x,y为一维数组
mport matplotlib.pyplot as plt
import numpy as np
import random
x=np.array([1,2,3,4,5,6,7,8,9,10,11])
y=np.array([1,2,3,4,5,2,5,6,7,8,3])
plt.bar(x,y,lw=1)#条形
plt.show()
mport matplotlib.pyplot as plt
import numpy as np
import random
x=np.array([1,2,3,4,5,6,7,8,9,10,11])
y=np.array([1,2,3,4,5,2,5,6,7,8,3])
plt.plot(x,y,'r',lw=1)#条形
plt.show()
x,y为二维数组
x=np.array([i for i in range(10)])
print(x)
y=np.array([x[i]*3-12 for i in range(10) ])# plt.plot(x,y,'r',lw=2)plt.show()x=np.array([[i,i] for i in range(20)] )
y=np.array([[i*i-10*i,-i*i+15*i] for i in range(20)])
print(x)
print("============================================================")
print(y)
print('+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
for i in range(20):if y[i][0]>y[i][1]:plt.plot(x[i],y[i],'r',lw=3)else:plt.plot(x[i], y[i], 'g', lw=3)
plt.show()