Multiple-row barcode error plots in pandas

I can build error lines on the lines of one row as follows:

import pandas as pd df = pd.DataFrame([[4,6,1,3], [5,7,5,2]], columns = ['mean1', 'mean2', 'std1', 'std2'], index=['A', 'B']) print(df) mean1 mean2 std1 std2 A 4 6 1 3 B 5 7 5 2 df['mean1'].plot(kind='bar', yerr=df['std1'], alpha = 0.5,error_kw=dict(ecolor='k')) 

enter image description here

As expected, the average value of index A is associated with the standard deviation of the same index, and the error line shows +/- of this value.

However, when I try to build both "average" and "average" in the same plot, I cannot use standard deviations in the same way:

 df[['mean1', 'mean2']].plot(kind='bar', yerr=df[['std1', 'std2']], alpha = 0.5,error_kw=dict(ecolor='k')) Traceback (most recent call last): File "<ipython-input-587-23614d88a3c5>", line 1, in <module> df[['mean1', 'mean2']].plot(kind='bar', yerr=df[['std1', 'std2']], alpha = 0.5,error_kw=dict(ecolor='k')) File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.py", line 1705, in plot_frame plot_obj.generate() File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.py", line 878, in generate self._make_plot() File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.py", line 1534, in _make_plot start=start, label=label, **kwds) File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\tools\plotting.py", line 1481, in f return ax.bar(x, y, w, bottom=start,log=self.log, **kwds) File "C:\Users\nameDropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\matplotlib\axes.py", line 5075, in bar fmt=None, **error_kw) File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\matplotlib\axes.py", line 5749, in errorbar iterable(yerr[0]) and iterable(yerr[1])): File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\core\frame.py", line 1635, in __getitem__ return self._getitem_column(key) File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\core\frame.py", line 1642, in _getitem_column return self._get_item_cache(key) File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\core\generic.py", line 983, in _get_item_cache values = self._data.get(item) File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\core\internals.py", line 2754, in get _, block = self._find_block(item) File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\core\internals.py", line 3065, in _find_block self._check_have(item) File "C:\Users\name\Dropbox\Tools\WinPython-64bit-2.7.6.2\python-2.7.6.amd64\lib\site-packages\pandas\core\internals.py", line 3072, in _check_have raise KeyError('no item named %s' % com.pprint_thing(item)) KeyError: u'no item named 0' 

The closest I got to my desired result is the following:

 df[['mean1', 'mean2']].plot(kind='bar', yerr=df[['std1', 'std2']].values.T, alpha = 0.5,error_kw=dict(ecolor='k')) 

enter image description here

But now error bars are not built symmetrically. Instead, the green and blurry stripes in each series use the same positive and negative error, and it is here that I am stuck. How can I get the error strings of my serial batch font to look similar when I only had one run?

Update: It looks like this is fixed in pandas 0.14 , I read the documents 0.13 earlier. I now have no way to update my pandas. Let's go later and see how it works out.

+6
source share
1 answer

Roger, what Ajan and Alios!

Well, finally, I found the answer to the question. This is what I tried to do in a few days. The problem was apparently a problem in an earlier version of Pandas. I installed Pandas 0.15.0, and now you can reference another data frame and use the data for error bars in grouped charts, as Keflo did above. Thus, the following code now works in Pandas 0.15.0.

 import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame([[4,6,1,3], [5,7,5,2]], columns = ['mean1', 'mean2', 'std1', 'std2'], index=['A', 'B']) print(df) df[['mean1', 'mean2']].plot(kind='bar', yerr=df[['std1', 'std2']].values.T, alpha = 0.5,error_kw=dict(ecolor='k')) plt.show() 
+6
source

All Articles