本帖最后由 a20150604 于 2021-4-19 19:53 编辑
- # encoding: utf-8
-
- import matplotlib.pyplot as plt
- # import matplotlib.pylab as plt
- from matplotlib.pyplot import figure
- import re
-
- o_img = '1.jpg'
- file = open('1.txt') #打开文档
- data = file.readlines() #读取文档数据
-
- cnt_data_lines = len(data)-1
- print(cnt_data_lines)
-
- num_of_lines = 7
-
- arr_data = [[0 for i in range(cnt_data_lines)] for i in range(num_of_lines + 1)]
- arr_tit = [0 for j in range(num_of_lines)]
-
- strinfo = re.compile(r'\s+') #
- i=1
- for num in data:
- if i>1 : # 数据区
- arr_data[num_of_lines][i-2]=i-1
- for j in range(num_of_lines):
- arr_data[j][i-2]=float(strinfo.sub(',', num).split(',')[j+1])
-
- else :
- for j in range(num_of_lines):
- arr_tit[j] = strinfo.sub(',', num).split(',')[j+1]
-
- i+=1
-
- # plt.figure()
- plt.figure(figsize=(8, 6), dpi=80)
- plt.title('map')
- plt.xlabel('x label')
- plt.ylabel('y label')
- plt.xticks(arr_data[num_of_lines], arr_data[num_of_lines]) #, rotation='vertical'
- arr_p = [0 for j in range(num_of_lines)]
- for k in range(num_of_lines):
- arr_p[k] , = plt.plot(arr_data[num_of_lines], arr_data[k],label=arr_tit[k])
- # plt.legend()
- plt.legend(loc='best')
- plt.savefig(o_img)
- plt.show()
复制代码
|