python 画条形图加误差线_使用matplotlib向图形添加误差线

所以现在,我正试图将错误栏添加到现有的图表中,但在运行代码时,我仍会遇到一些错误。下面是我添加的内容被注释掉时的代码(没有错误条)。从中提取信息的文件包含4列,其中第4列是垂直错误。当我运行包含注释行的代码时,会得到以下错误Traceback (most recent call last):

File “39.py”, line 37, in

plot_graph()

File “39.py”, line 29, in plot_graph

plt.errorbar(x1,y1, yerr = z1, marker = ‘none’, linestyle = ‘none’)

File “/Users/Bashe/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/pyplot.py”, line 2697, in errorbar

errorevery=errorevery, capthick=capthick, **kwargs)

File “/Users/Bashe/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/axes.py”, line 5758, in errorbar

in cbook.safezip(y, yerr)]

TypeError: unsupported operand type(s) for -: ‘str’ and ‘str’

这是我的密码。希望有人能告诉我是什么导致了这个问题。import os

import pylab as plt

def plot_graph():

file=’Graph.txt’

x = []

y = []

z = []

x1 = []

y1 = []

z1 = []

t = []

t1 = []

for dirpath,dirs,files in os.walk(‘/Users/Bashe/Desktop/121210 p2/’):

if file in files:

infile = open(os.path.join(dirpath, “Graph.txt”), “r”)

for columns in (raw.strip().split() for raw in infile):

t = columns[0]

x = columns[1]

y = columns[2]

z = columns[3]

x1.append(str(x))

y1.append(str(y))

z1.append(str(z))

t1.append(str(t))

savepath = os.path.join(dirpath, ‘Mean vs Temperature for %s.png’ %(t1[0]))

plt.plot(x1,y1, marker =’o’, linestyle = ‘–‘)

plt.errorbar(x1,y1, yerr = z1, marker = ‘none’, linestyle = ‘none’)

plt.xlabel(‘Temperature’)

plt.ylabel(‘Mean’)

plt.title(‘Mean vs Temperature for %s probe concentration’ %(t1[0]))

plt.savefig(savepath)

plt.show()

infile.close()

Original: https://blog.csdn.net/weixin_32667011/article/details/113643132
Author: malartinla
Title: python 画条形图加误差线_使用matplotlib向图形添加误差线

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/769554/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球