简体   繁体   中英

how do I add error bars to a grouped bar chart with python pandas?

I know there is a very related question here . However, the solution there works for that example, but it is giving me an error still.

Here is my fairly simple code:

I am trying to add error bars to my grouped bar chart.

df = pd.DataFrame([[ 1306,  5148,  1729,  1377,  1051,   179,  7250],
       [ 2202,  8445,  2749,  1573,  1898,   292, 11466],
       [   46,   281,    71,    53,    35,     4,   293],
       [  445,  1701,   553,   470,   355,    53,  3088],
       [  145,   583,   190,   100,   138,    16,  1505],
       [  164,   476,   164,    72,   188,    12,  1311],
       [  174,   842,   254,   129,   177,    34,  2599]])
df.columns = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
df.index = ['a', 'b', 'c', 'd', 'e', 'f', 'g']

yerr = array([[ 0.00192938,  0.001575  ,  0.00840369,  0.00305756,  0.00437465,
         0.00517742,  0.00306851],
       [ 0.00336221,  0.00269552,  0.01714203,  0.00534033,  0.00797719,
         0.00817815,  0.00616608],
       [ 0.00219171,  0.00174148,  0.01026187,  0.00337873,  0.00496298,
         0.00517742,  0.00367047],
       [ 0.00197692,  0.00134693,  0.00897753,  0.00313595,  0.00366509,
         0.00350077,  0.00265679],
       [ 0.00174394,  0.00147064,  0.00738486,  0.00275061,  0.00427364,
         0.00551332,  0.0030937 ],
       [ 0.00073795,  0.00059391,  0.00254775,  0.00108794,  0.00148974,
         0.00144758,  0.00137975],
       [ 0.00365027,  0.00289623,  0.01729375,  0.00610798,  0.00958869,
         0.01018425,  0.00749114]])

df.plot(kind='bar', yerr=yerr)

Gives a

ValueError: too many values to unpack

Any ideas why? I thought yerr had the be the same shape as the df (which it is)

apparently there was an issue with Pandas 0.13. This was solved in 0.14. Thanks to @chrisb for confirming and sorting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM