123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #!/usr/bin/python
- # -*- coding: UTF-8 -*-
- import matplotlib.pyplot as plt
- import numpy as np
- #绘制散点图
- def drawScatter(heights,weights):
- #创建散点图
- #第一个参数为点的横坐标
- #第二个参数为点的纵坐标
- plt.scatter(heights,weights)
- plt.xlabel('Heights')
- plt.ylabel('Weight')
- plt.title('Heights & Weight of Students')
- plt.show()
- def drawLine(w, b):
- plt.xlabel("x")
- plt.ylabel("y")
- x = np.arange(0, 10)
- y = w*x + b
- plt.plot(x, y)
- plt.show()
- def drawScatterAndLine(p, q, w, b):
- plt.scatter(p, q)
- plt.xlabel('p')
- plt.ylabel('q')
- plt.title('line regesion')
- x = np.arange(0, 11)
- y = w * x + b
- plt.plot(x, y, color='red')
- plt.show()
- if __name__ == '__main__':
- heights = [1.5, 1.7]
- weights = [43, 61]
- drawScatter(heights,weights)
- drawLine(1,2)
|