Reputation: 1
I'm trying to plot an error bar, but it's not working and it's returning a traceback ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). I have no idea how to deal with it. I'm a python begginer.
This is the code:
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()
This is the traceback:
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().
Can someone help me?
Thanks
Upvotes: 0
Views: 10738
Reputation: 1324
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()
I think the yerr of your code might have some issues. Check it, that what does it contains. It should contain a nice series in one dimension i guess.
Upvotes: 3