• Python中读取txt文本中的输入,输出,w,b等数据,并画出其分布图


    #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()



  • 相关阅读:
    webpack篇
    js 中对于this 的理解的 经典案例
    AMD、CMD、CommonJs和es6对比
    vue import异步加载js
    vscode 保存自动 格式化eslint 代码
    git设置
    面向对象的三大特性之继承
    面向对象 类与对象及其属性与方法 类的组合
    hashlib模块 hash算法
    configparser模块 配置文件的解析操作
  • 原文地址:https://www.cnblogs.com/LJW-XJTU/p/8416298.html
Copyright © 2020-2023  润新知