Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib with Pandas: Elementwise comparison failed

I am building a bar chart with pandas and matplotlib. I need error bars, but my function does not create them and I get the following message:

C:\Python27\lib\site-packages\matplotlib\collections.py:590: FutureWarning: elementwise comparison failed; returning sca
lar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

According to the pandas plotting documentation:

The error values can be specified using a variety of formats.

As a DataFrame or dict of errors with column names matching the columns attribute of the plotting DataFrame or matching the name attribute of the Series
As a str indicating which of the columns of plotting DataFrame contain the error values
As raw values (list, tuple, or np.ndarray). Must be the same length as the plotting

I have the following:

recsFrame_mean = recsFrame.groupby('REGIONC').mean()

recsFrame_mean.plot(y='weighted_KWH',yerr='se_KWH', kind='bar')

recsFrame_mean has the structure:

>>> print(recsFrame_mean)
         DIVISION  REPORTABLE_DOMAIN   TYPEHUQ       NWEIGHT        HDD65  \
REGIONC
1        1.586055           2.734775  2.997793   9166.128420  5894.129303
2        3.595498           9.556806  2.476609   9116.257475  6285.651425
3        5.751589          17.612958  2.558924  10288.546455  2436.917604
4        9.564147          25.390777  2.717060   8615.848474  3067.628294

             ...       PERIODLP   SCALELP  PERIODFO   SCALEFO  PERIODKR  \
REGIONC      ...
1            ...      -1.536187 -1.684025 -0.392763 -0.897617 -1.854810
2            ...      -1.523039 -1.676750 -1.906437 -1.934576 -1.945480
3            ...      -1.528117 -1.679951 -1.945477 -1.963325 -1.951100
4            ...      -1.650485 -1.758322 -1.971221 -1.980583 -1.968793

         SCALEKER   NGHSQFT  ELECHSQFT  weighted_KWH        se_KWH
REGIONC
1       -1.897617  0.402426   5.895109  7.407772e+07   7923.790058
2       -1.962715  0.405440   7.297165  9.647961e+07  11282.706985
3       -1.966259  0.138032  10.506909  1.498108e+08  14699.751866
4       -1.978155  0.299447   7.095108  8.017829e+07   8982.045134

[4 rows x 931 columns]
like image 702
Jason Hawkins Avatar asked Dec 01 '25 16:12

Jason Hawkins


1 Answers

I've had issues with plotting error bars through pandas being flaky sometimes. Try yerr=list(recsFrame_mean['se_KWH']) as I think that's been a consistently working method for me.

like image 129
Randy Avatar answered Dec 04 '25 08:12

Randy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!