条形图中的标准偏差误差条

时间:2021-06-20 16:03:12

标签: python std errorbar

我正在尝试绘制一个误差条,但它不起作用并且它返回了一个回溯 ValueError:一个系列的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。 我不知道如何处理它。我是一名蟒蛇初学者。

这是代码:

width = 10
height = 8
plt.figure(figsize=(width, height))
plt.bar(x, y, color=['lightgray','plum','plum','plum','lightblue','lightblue','lightblue','palegreen','palegreen','palegreen', 'khaki', 'khaki', 'khaki'])
plt.title('PNT1A Cell viability: Chlorpromazine, Filipin, Wortmannin and SB421543')
plt.xlabel('Inhibitor concentration (uM)')
plt.ylabel('Viability %')
plt.errorbar(x, y, yerr, fmt='.', color='Black', elinewidth=2,capthick=10,errorevery=1, alpha=0.5, ms=4, capsize = 2)
plt.savefig('figure.png', dpi=400, transparent=True)
plt.show()

这是回溯:

ValueError                                Traceback (most recent call last)
<ipython-input-124-200e4c94cc0c> in <module>
      6 plt.xlabel('Inhibitor concentration (uM)')
      7 plt.ylabel('Viability %')
----> 8 plt.errorbar(x, y, yerr, fmt='.',color='Black',elinewidth=2,capthick=10,errorevery=1,alpha=0.5,ms=4,capsize=2)
      9 plt.savefig('figure.png', dpi=400, transparent=True)
     10 plt.show()

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/pyplot.py in errorbar(x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, data, **kwargs)
   2602         uplims=False, xlolims=False, xuplims=False, errorevery=1,
   2603         capthick=None, *, data=None, **kwargs):
-> 2604     return gca().errorbar(
   2605         x, y, yerr=yerr, xerr=xerr, fmt=fmt, ecolor=ecolor,
   2606         elinewidth=elinewidth, capsize=capsize, barsabove=barsabove,

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1445     def inner(ax, *args, data=None, **kwargs):
   1446         if data is None:
-> 1447             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1448 
   1449         bound = new_sig.bind(ax, *args, **kwargs)

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_axes.py in errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
   3452         if yerr is not None:
   3453             lower, upper = extract_err('y', yerr, y, lolims, uplims)
-> 3454             barcols.append(self.vlines(
   3455                 *apply_mask([x, lower, upper], everymask), **eb_lines_style))
   3456             # select points without upper/lower limits in y and

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1445     def inner(ax, *args, data=None, **kwargs):
   1446         if data is None:
-> 1447             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1448 
   1449         bound = new_sig.bind(ax, *args, **kwargs)

~/opt/anaconda3/lib/python3.8/site-packages/matplotlib/axes/_axes.py in vlines(self, x, ymin, ymax, colors, linestyles, label, **kwargs)
   1267             minx = x.min()
   1268             maxx = x.max()
-> 1269             miny = min(ymin.min(), ymax.min())
   1270             maxy = max(ymin.max(), ymax.max())
   1271 

~/opt/anaconda3/lib/python3.8/site-packages/numpy/core/_methods.py in _amin(a, axis, out, keepdims, initial, where)
     41 def _amin(a, axis=None, out=None, keepdims=False,
     42           initial=_NoValue, where=True):
---> 43     return umr_minimum(a, axis, None, out, keepdims, initial, where)
     44 
     45 def _sum(a, axis=None, dtype=None, out=None, keepdims=False,

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py in __nonzero__(self)
   1440     @final
   1441     def __nonzero__(self):
-> 1442         raise ValueError(
   1443             f"The truth value of a {type(self).__name__} is ambiguous. "
   1444             "Use a.empty, a.bool(), a.item(), a.any() or a.all()."

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

有人可以帮我吗?

谢谢

1 个答案:

答案 0 :(得分:0)

import matplotlib.pyplot as plt 
x=[1,2,3,4,5]
y=[6,7,8,9,10]
yerr=[0.1,0.2,0.3,0.4,0.5]
width = 10
height = 8
plt.figure(figsize=(width, height))
plt.bar(x, y, color=['lightgray','plum','plum','plum','lightblue','lightblue','lightblue','palegreen','palegreen','palegreen', 'khaki', 'khaki', 'khaki'])
plt.title('PNT1A Cell viability: Chlorpromazine, Filipin, Wortmannin and SB421543')
plt.xlabel('Inhibitor concentration (uM)')
plt.ylabel('Viability %')
plt.errorbar(x, y, yerr, fmt='.', color='Black', elinewidth=2,capthick=10,errorevery=1, alpha=0.5, ms=4, capsize = 2)
plt.savefig('figure.png', dpi=400, transparent=True)
plt.show()

enter image description here

我认为您的代码可能存在一些问题。检查它,它包含什么。我猜它应该包含一个很好的一维系列。