Tôi gặp vấn đề khi tạo biểu đồ từ các đối tượng chuỗi gấu trúc và tôi không thể hiểu tại sao nó không hoạt động. Các mã đã làm việc tốt trước nhưng bây giờ nó không.Lỗi Matplotlib/Pandas sử dụng biểu đồ
Dưới đây là một chút của mã của tôi (cụ thể là, một đối tượng loạt gấu trúc Tôi đang cố gắng để tạo ra một biểu đồ của):
type(dfj2_MARKET1['VSPD2_perc'])
mà kết quả đầu ra kết quả: pandas.core.series.Series
Dưới đây là âm mưu của tôi mã:
fig, axes = plt.subplots(1, 7, figsize=(30,4))
axes[0].hist(dfj2_MARKET1['VSPD1_perc'],alpha=0.9, color='blue')
axes[0].grid(True)
axes[0].set_title(MARKET1 + ' 5-40 km/h')
thông báo lỗi:
AttributeError Traceback (most recent call last)
<ipython-input-75-3810c361db30> in <module>()
1 fig, axes = plt.subplots(1, 7, figsize=(30,4))
2
----> 3 axes[1].hist(dfj2_MARKET1['VSPD2_perc'],alpha=0.9, color='blue')
4 axes[1].grid(True)
5 axes[1].set_xlabel('Time spent [%]')
C:\Python27\lib\site-packages\matplotlib\axes.pyc in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
8322 # this will automatically overwrite bins,
8323 # so that each histogram uses the same bins
-> 8324 m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
8325 m = m.astype(float) # causes problems later if it's an int
8326 if mlast is None:
C:\Python27\lib\site-packages\numpy\lib\function_base.pyc in histogram(a, bins, range, normed, weights, density)
158 if (mn > mx):
159 raise AttributeError(
--> 160 'max must be larger than min in range parameter.')
161
162 if not iterable(bins):
AttributeError: max must be larger than min in range parameter.
Hmm, nó làm việc cho tôi. Bạn có thể hiển thị khung dữ liệu của mình không? –
Hmm, lạ khi tôi làm điều này tôi thực sự có thể tạo ra một biểu đồ: s = dfj2_MARKET1 ['VSPD1_perc'] s.hist() – jonas
Có, nhưng sau đó bạn đang sử dụng chức năng 'hist' gấu trúc, và không phải matplotlibs. Và điều này xử lý ví dụ như NaNs như mong đợi. Xem cập nhật của tôi. – joris