python中用于绘图是matplotlib模块中的pyplot类,直接使用plot()函数绘制出的是折线图。而绘制散点图使用的是scatter()函数。
直接看下面的代码
#-*- coding: UTF-8 -*-
import matplotlib.pyplot as plt
def scatter_test():
#define points list
points = [(10, 20), (25, 40), (80, 60), (60, 90), (10, 20), (80, 90), (50, 60), (30, 80)]
x, y = zip(*points)
plt.figure()
plt.scatter(x, y)
plt.show()
return
def main():
scatter_test()
return
if __name__ == "__main__":
main()