Tôi đang gặp khó khăn khi cố vẽ biểu đồ bằng python, numpy và matplotlib trên mac osx. Tôi có điều này làm việc một cách hoàn hảo 6 months ago tuy nhiên cùng mã sản xuất lỗi này:LoạiError: biểu đồ() nhận được đối số từ khóa không mong muốn 'mới'
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)
Trả về thông báo sau:
---------------------------------------------------------------------------
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''
Tôi đã cố gắng để gỡ bỏ cài đặt và cài đặt lại trăn, ipython, numpy, matplotlib và scipy và cài đặt chúng trong /usr/local/bin
mặc dù lỗi vẫn tồn tại.
Có ai đã xem vấn đề này trước hoặc sẽ biết giải pháp khả thi không? Cảm ơn
Bạn có thể cung cấp mã * chính xác * đã tạo ra lỗi không? Dường như nó đã xảy ra trên dòng 10, nhưng 'In [2]' của bạn chỉ có 9 dòng (và các kwarg khác). Và bạn cũng có thể thử chỉ cần nhập 'plt' và' randn'? – hitzg
Mã trong traceback khác với mã bạn đã viết ở trên: 'plt.hist (dữ liệu, thùng = 20, mật độ = True)' vs 'plt.hist (dữ liệu)' –
Xin lỗi, tôi đã sử dụng 'plt.hist (dữ liệu, thùng = 20, mật độ = True) 'trong ví dụ ban đầu sau đó tôi gỡ bỏ nó và có các thiết bị đầu cuối trộn lẫn lên. các lỗi chính xác xảy ra với cả hai tuy nhiên. Tôi vẫn nhận được 'TypeError: histogram() có một đối số từ khóa không mong muốn 'new''' cho bboth –