标签:data mat pyplot for 哪些 出现 line color app
1 #从文本中获取,并且统计 2 import matplotlib.pyplot as plt 3 import numpy as np 4 5 6 f = open(‘TXT/123.txt‘) 7 lines = f.readlines() 8 data = [] 9 10 for line in lines: 11 data.append(int(line)) 12 data = sorted(data) 13 print(data) 14 15 unique_data = np.unique(data) 16 print(unique_data) 17 18 resdata = [] 19 for ii in unique_data: 20 resdata.append(data.count(ii)) 21 print(resdata) 22 23 fig = plt.figure() 24 plt.plot(unique_data, resdata) 25 plt.show()
y = sorted(y) print(y) #统计出现的元素有哪些 unique_data = np.unique(y) print(unique_data) #统计某个元素出现的次数 resdata = [] for ii in unique_data: resdata.append(y.count(ii)) print(resdata)
标签:data mat pyplot for 哪些 出现 line color app
原文地址:https://www.cnblogs.com/miaoqianling/p/11444015.html