python - errorbar 函数错误 matplotlib.pyplot
问题描述
我正在尝试定义一个函数,该函数会为 y 的某些给定值及其错误以及 x 值及其输入的错误生成带有误差线的散点图。我对此比较陌生,无法完全破译回溯错误。我编写的函数适用于 scatter(),但不适用于 errorbar()。任何对正确方向的点头,即使它只是解释回溯,将不胜感激。
import matplotlib.pyplot as plt
import numpy as np
def definedscatter(yvalues,xax,yax):
print('When entering data, type "done" to finish input for the current variable.')
plt.figure(1)
xvalues=[]
xerrors=[]
i=1
xn=None
while True:
try:
xn=input('x value #'+str(i)+': ')
if xn=='done':
break
else:
test1=float(xn)
xnerr=input('Error in x value #'+str(i)+': ')
if xnerr=='done':
break
else:
test2=float(xnerr)
xnli=[xn]
xnerrli=[xnerr]
i=i+1
xvalues=xvalues+xnli #can't concatenate float to list, only list
xerrors=xerrors+xnerrli
except:
print('Please enter a numerical value, or type "done" if you have finished inputting data.')
plt.errorbar(xvalues,yvalues, xerr=xerrors , yerr=yerrors , fmt='o') #scatter func program works fine, but errorbar doesn't, so something wrong with func args
plt.xlabel(xax)
plt.ylabel(yax)
plt.show()
y=[1,2,4,9]
yerrors=[0.3,0.2,0.5,0.8]
xaxis=input('x axis: ')
yaxis=input('y axis: ')
definedscatter(y,xaxis,yaxis)
解决方案
推荐阅读
- html - 带有可滚动表格主体的 CSS 100% 高度布局
- sql - SQL - 从数组中提取 JSON
- android - (Uber RIBs) 跨 RIBs 传递数据
- android - 导航架构组件推送和弹出功能
- css - laravel 在 npm run dev 后生成 css
- git - gitflow 拉取并使用远程分支
- android - 在whatsapp贴纸包应用程序中使用相机图像或图库图像自定义贴纸
- sql-server - SQL Server Management Studio 使用 FOR XML PATH 连接多行
- python - 大熊猫中的交叉加法
- python - 在python中打印具有条件的相同级别的xml数据