#read input,output,w,b data,画出其分析图
import os
import math
import numpy as np
import matplotlib.pyplot as plt
#filename='b'+i+'_'+j+'.txt'
#filename='w'+i+'_'+j+'.txt'
#filename='output'+i+'_'+j+'.txt'
#filename='input1.txt'
#filename =input("please input the filename:")
#依次遍历每一个txt文件
for i in range (6):
for j in range (5):
filename='b'+str(i)+'_'+str(j)+'.txt'
if os.path.exists(filename): #判断文件是否存在
print(filename)
data = np.loadtxt(filename) #用numpyload文本
l=len(data)
print(l)
num_bins=l #是画直方图中hist的属性,主要用来表示横坐标分组的个数
plt.hist(data,num_bins)#,normed=0,histtype='bar',facecolor='yellowgreen',alpha=0.75,rwidth=0.5
plt.title(filename) #plt出图的标题显示
plt.savefig('/data1/ljw/Documents/W_graph/graph/'+filename+'.png') #自动将图像保存的路径
plt.close() #每输出一个图像后,在输出下一幅图像之前关闭当前图像,防止叠加
# plt.subplots_adjust(hspace=0.4)
#plt.show()
filename='b_f.txt'
if os.path.exists(filename):
print(filename)
data = np.loadtxt(filename)
l=len(data)
print(l)
num_bins=l
plt.hist(data,num_bins)
plt.title(filename)
plt.savefig('/data1/ljw/Documents/W_graph/graph/'+filename+'.png')
plt.close()
#plt.show()
for i in range (6):
for j in range (5):
filename='w'+str(i)+'_'+str(j)+'.txt'
if os.path.exists(filename):
print(filename)
data = np.loadtxt(filename)
l=len(data)
print(l)
num_bins=400
plt.hist(data,num_bins)
plt.title(filename)
plt.savefig('/data1/ljw/Documents/W_graph/graph/'+filename+'.png')
plt.close()
#plt.show()
filename='out1_2.txt'
if os.path.exists(filename):
print(filename)
data = np.loadtxt(filename)
l=len(data)
print(l)
num_bins=200
plt.hist(data,num_bins)
plt.title(filename)
plt.savefig('/data1/ljw/Documents/W_graph/graph/'+filename+'.png')
plt.show()
plt.close()
print(10)
for i in range (6):
for j in range (5):
filename='out'+str(i)+'_'+str(j)+'.txt'
if os.path.exists(filename):
print(filename)
data = np.loadtxt(filename)
l=len(data)
print(l)
num_bins=20
plt.hist(data,num_bins)
plt.title(filename)
plt.savefig('/data1/ljw/Documents/W_graph/graph/'+filename+'.png')
plt.close()
#plt.show()
filename='input1.txt'
if os.path.exists(filename):
print(filename)
data = np.loadtxt(filename)
l=len(data)
print(l)
num_bins=400
plt.hist(data,num_bins)
plt.title(filename)
plt.savefig('/data1/ljw/Documents/W_graph/graph/'+filename+'.png')
#plt.show()
plt.close()
filename='output.txt'
if os.path.exists(filename):
print(filename)
data = np.loadtxt(filename)
l=len(data)
print(l)
num_bins=400
plt.hist(data,num_bins)
plt.title(filename)
plt.savefig('/data1/ljw/Documents/W_graph/graph/'+filename+'.png')
#plt.show()
plt.close()