实现线性回归可视化
import numpy as np
import matplotlib.pyplot as plt
x=[1,2,5,3,5]
y=[1,5,8,10,16]
plt.plot(x,y,"ro")
plt.axis([1,7,1,21])
plt.plot(np.unique(x),np.poly1d(np.polyfit(x,y,1))(np.unique(x)))
plt.show()
import matplotlib.pyplot as plt
import numpy as np
a = np.arange(10)
plt.plot(a,a*1.5,'go-',a,a*2.5,'rx',a,a*3.5,'*',a,a*4.5,'b-.')
plt.show()
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 1, 101)
y = np.sin(2*np.pi*x)
plt.figure()
plt.plot(x, y, label="$\sin(x)$", c='b')
plt.xlabel('x', fontdict=dict(fontsize=14))
plt.ylabel('y', fontdict=dict(fontsize=14))
plt.legend()
plt.show()
以上为一些关于matplotlib的其他操作