Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:histogram()获取了意外的关键字参数';新';_Python_Macos_Numpy_Matplotlib - Fatal编程技术网

Python TypeError:histogram()获取了意外的关键字参数';新';

Python TypeError:histogram()获取了意外的关键字参数';新';,python,macos,numpy,matplotlib,Python,Macos,Numpy,Matplotlib,我很难在MacOSX上使用python、numpy和matplotlib绘制直方图。我在6个月前就让它工作得很好,但是相同的代码会产生以下错误: 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.p

我很难在MacOSX上使用python、numpy和matplotlib绘制直方图。我在6个月前就让它工作得很好,但是相同的代码会产生以下错误:

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''
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
8.
9数据=随机数(75)
--->10 plt.hist(数据,箱=20,密度=True)
/hist中的System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/pyplot.pyc(x、bin、range、normed、weights、cumulative、bottom、histtype、align、orientation、rwidth、log、color、label、hold、**kwargs)
2339斧头保持(保持)
2340请尝试:
->2341 ret=最大历史(x、箱子、范围、规格、重量、累计、底部、历史类型、对齐、方向、rwidth、日志、颜色、标签,**kwargs)
2342 draw_if_interactive()
2343最后:
/hist中的System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib/axes.pyc(self、x、bin、range、normed、weights、cumulative、bottom、histtype、align、orientation、rwidth、log、color、label、**kwargs)
7734#这将自动覆盖垃圾箱,
7735#因此每个直方图使用相同的箱子
->7736米,箱子=np。柱状图(x[i],箱子,重量=w[i],**历史重量)
7737如果标准化:
7738 db=净压差(箱)
TypeError:histogram()获得意外的关键字参数“new”
我尝试卸载并重新安装python、ipython、numpy、matplotlib和scipy,并将它们安装在
/usr/local/bin
中,但错误仍然存在


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

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

在OSX中,我不得不手动删除matplotlib库:
rm-rf/System/library/Frameworks/Python.framework/Versions/2.7/Extras/lib/Python/matplotlib

然后我卸载了matplotlib:
sudopip卸载matplotlib
我重新安装了
matplotlib
sudo-pip-install-matplotlib==1.5.1


这似乎对我有效。

您能提供产生错误的确切代码吗?它似乎发生在第10行,但是[2]中的
只有9行(和其他KWARG)。你也可以尝试导入
plt
randn
?回溯中的代码与你上面写的代码不同:
plt.hist(data,bins=20,density=True)
vs
plt.hist(data)
对不起,我确实使用了
plt.hist(data,bins=20,density=True)
在最初的示例中,我将其删除,使终端混淆。然而,两者都会出现确切的错误。我仍然得到了
TypeError:histogram()得到了一个意外的关键字参数“new”
当我运行代码示例(Matplotlib版本1.4.3、Numpy版本1.8.1、Scipy版本0.15.1)时,BBoth不会发生。