Python带误差棒的折线图

步骤

1 读文本
2 做带误差棒的折线图

代码

import math
import matplotlib.pyplot as plt 
import seaborn as sns 
import pandas as pd                                                                                                                                                                                              
import numpy as np

def analyzeError(filename):
    sampleSigma = []
    list_Error = []
    list_StdDev = []

    data = open(filename)
    lines = data.readlines()
    data.close()

    for line in lines:
        line = line.strip()
        eles = line.split()
        sampleSigma.append(float(eles[0]))
        list_Error.append(float(eles[1]))
        list_StdDev.append(float(eles[2]))

    print(sampleSigma)
    print(list_Error)
    print(list_StdDev)

    plt.errorbar(sampleSigma,list_Error,yerr=list_StdDev,fmt='ko-',ecolor='k',elinewidth=3,ms=5,mfc='wheat',mec='salmon',capsize=3)
        

    return

# main
print("hello")

#
fig = plt.figure(figsize=(4,3))
ax = plt.subplot(111)
plt.subplots_adjust(left=0.14, bottom=0.20, right=None, top=None,wspace=None, hspace=None)

#
analyzeError("log_error_0weight.txt")
analyzeError("log_error.txt")

plt.xlabel(r'$\sigma_{Ti,Aj}\ /\ dBm$',fontdict={'family' : 'Times New Roman', 'size': 12})
plt.ylabel("Error / m",fontdict={'family' : 'Times New Roman', 'size': 12})
#plt.savefig('figure-ErrorDistributionAll.png',dpi=300)
plt.show()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容