用matplotlib模块

#!usr/bin/env python
#encoding:utf-8 '''
__Author__:沂水寒城
功能:折线图、散点图测试
''' import random
import matplotlib
import matplotlib.pyplot as plt def list2mat(data_list,w):
'''
切片、转置
'''
mat=[]
res=[]
for i in range(0,len(data_list)-w+1,w):
mat.append(data_list[i:i+w])
for i in range(len(mat[0])):
one_list=[]
for j in range(len(mat)):
one_list.append(mat[j][i])
res.append(one_list)
return res def draw_pic_test():
'''
作图
'''
data_list=[]
for i in range(100):
data_list.append(random.randint(2,150))
month_list=range(1,11,1)
mat=list2mat(data_list,w=10)
for one_list in mat:
one_list=[int(one) for one in one_list]
plt.plot(month_list,one_list,"x-",label="test_zhexian")
plt.savefig('test_zhexian.png')
plt.close()
for one_list in mat:
one_list=[int(one) for one in one_list]
plt.scatter(month_list,one_list,marker='x',label='test_sandian',s=30)
plt.savefig('test_sandian.png')
plt.close() if __name__ == '__main__':
draw_pic_test()

结果

折线图

散点图