[英]TypeError: histogram() got an unexpected keyword argument 'new'
I'm having a hard time trying to plot histograms using python, numpy and matplotlib on a mac osx. 我在尝试在Mac OS X上使用python,numpy和matplotlib绘制直方图时遇到了困难。 I had this working perfectly 6 months ago however the same code produces this error:
我在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)
Returns the following message: 返回以下消息:
---------------------------------------------------------------------------
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''
I have attempted to uninstall and reinstall python, ipython, numpy, matplotlib and scipy and install them in /usr/local/bin
though the error persists. 我尝试卸载并重新安装python,ipython,numpy,matplotlib和scipy,然后将它们安装在
/usr/local/bin
尽管错误仍然存在。
Has anyone seen this issue before or would know a possible solution? 有没有人看过这个问题,或者知道可能的解决方案? Thanks
谢谢
For me the comment from cphlewis was the hint I needed. 对我来说,cplewis的评论是我需要的提示。 I was working with matplotlib 1.1, and after an update to 1.5 everything works fine for me.
我使用的是matplotlib 1.1,更新到1.5后,一切对我来说都很好。
In OSX, I had to manually delete the matplotlib library: rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib
在OSX中,我必须手动删除matplotlib库:
rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib
Then I uninstalled the matplotlib: sudo pip uninstall matplotlib
and I re-installed matplotlib
: sudo pip install matplotlib==1.5.1
然后,我卸载了matplotlib:
sudo pip uninstall matplotlib
然后重新安装了matplotlib
: sudo pip install matplotlib==1.5.1
This seemed to work for me. 这似乎对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.