【问题标题】:Matplotlib with Pandas: Elementwise comparison failed带有 Pandas 的 Matplotlib:元素比较失败
【发布时间】:2015-08-20 05:35:20
【问题描述】:

我正在使用 pandas 和 matplotlib 构建条形图。我需要错误栏,但我的函数没有创建错误栏,我收到以下消息:

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'):

根据熊猫绘图文档:

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

我有以下几点:

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

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

recsFrame_mean 的结构如下:

>>> 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]

【问题讨论】:

    标签: python pandas matplotlib


    【解决方案1】:

    有时我在通过 pandas 绘制误差线时遇到问题。试试yerr=list(recsFrame_mean['se_KWH']),因为我认为这对我来说一直是一种工作方法。

    【讨论】:

    • 我得到了同样的错误。我可以在提示符中运行每一行而不会出错,但是在运行时会出现上面提到的错误:plt.show()。它绘制没有误差线。我还尝试将绘图保存到图像中,但得到相同的图像而没有错误栏。
    • 我再次查看了我的数字,看起来错误只是小了几个数量级。这可能是问题所在。
    猜你喜欢
    • 2021-03-04
    • 2018-07-26
    • 2020-04-07
    • 2017-04-01
    • 2019-11-25
    • 2020-03-04
    • 2016-08-05
    • 2017-11-26
    • 1970-01-01
    相关资源
    最近更新 更多