TypeError:histogram()得到了意外的关键字参数"new" [英] TypeError: histogram() got an unexpected keyword argument 'new'

查看:101
本文介绍了TypeError:histogram()得到了意外的关键字参数"new"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难在Mac OS X上尝试使用python,numpy和matplotlib绘制直方图. 6个月前,我已经完美运行了,但是相同的代码会产生此错误:

I'm having a hard time trying to plot histograms using python, numpy and matplotlib on a mac osx. I had this working perfectly 6 months ago however the same code produces this error:

In [1]: %matplotlib inline

In [2]:import numpy as np
       from numpy.random import randn
       import pandas as pd
       import matplotlib as mpl
       import matplotlib.pyplot as plt
       from scipy import stats

       data = randn(75)
       plt.hist(data)

返回以下消息:

    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-2-fa104aadeee7> in <module>()
      8 
      9 data = randn(75)
---> 10 plt.hist(data,bins=20, density=True)

     /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.pyc in hist(x, bins, range, normed, weights, cumulative, bottom,  histtype, align, orientation, rwidth, log, color, label, hold, **kwargs)
   2339         ax.hold(hold)
   2340     try:
-> 2341         ret = ax.hist(x, bins, range, normed, weights, cumulative,  bottom,     histtype, align, orientation, rwidth, log, color, label, **kwargs)
   2342         draw_if_interactive()
   2343     finally:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, **kwargs)
   7734             # this will automatically overwrite bins,
   7735             # so that each histogram uses the same bins
-> 7736             m, bins = np.histogram(x[i], bins, weights=w[i],     **hist_kwargs)
   7737             if normed:
   7738                 db = np.diff(bins)

TypeError: histogram() got an unexpected keyword argument 'new''

我尝试卸载并重新安装python,ipython,numpy,matplotlib和scipy,然后将它们安装在/usr/local/bin中,尽管错误仍然存​​在.

I have attempted to uninstall and reinstall python, ipython, numpy, matplotlib and scipy and install them in /usr/local/bin though the error persists.

有人有没有看过这个问题,或者知道可能的解决方案?谢谢

Has anyone seen this issue before or would know a possible solution? Thanks

推荐答案

对我来说,phphlewis的评论是我需要的提示.我使用的是matplotlib 1.1,更新到1.5后,一切对我来说都很好.

For me the comment from cphlewis was the hint I needed. I was working with matplotlib 1.1, and after an update to 1.5 everything works fine for me.

这篇关于TypeError:histogram()得到了意外的关键字参数"new"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆