TypeError:切片索引必须为整数或无,或者具有索引方法生成不完整的图

时间:2019-04-09 20:19:55

标签: python python-3.x jupyter-notebook typeerror

我无法在输出中生成图形。第一张图将生成不正确,但会显示出来,与其他图不同。

我尝试更新所有软件并更改部分代码,但对我而言不起作用。我不太确定如何更改子代码,或者是否应该更改任何子代码。

我读过几个类似的代码错误,但它们是针对数组的。我对编码还是很陌生,因此任何帮助/提示都将对我有很大帮助!

Input

fig, ax = plt.subplots(2,2,figsize=(20, 10), sharex=False, sharey = False)
sb.despine(left=True)
sb.distplot(train['pickup_latitude'].values, label = 'pickup_latitude',color="g",bins = 100, ax=ax[0,0])
sb.distplot(train['dropoff_latitude'].values, label = 'dropoff_latitude',color="r",bins = 100, ax=ax[0,1])
sb.distplot(train['pickup_longitude'].values, label = 'pickup_longitude',color="g",bins = 100, ax=ax[1,0])
sb.distplot(train['dropoff_longitude'].values, label = 'dropoff_longitude',color="r",bins = 100, ax=ax[1,1])

Output
TypeError Traceback (most recent call last)
in ()
2 fig, ax = plt.subplots(2,2,figsize=(20, 10), sharex=False, sharey = False)
3 sb.despine(left=True)
----> 4 sb.distplot(train['pickup_latitude'].values, label = 'pickup_latitude',color="g",bins = 100, ax=ax[0,0])
5 sb.distplot(train['dropoff_latitude'].values, label = 'dropoff_latitude',color="r",bins = 100, ax=ax[0,1])
6 sb.distplot(train['pickup_longitude'].values, label = 'pickup_longitude',color="g",bins = 100, ax=ax[1,0])

/Users/Kvera40/anaconda/lib/python3.6/site-packages/seaborn/distributions.py in distplot(a, bins, hist, kde, rug, fit, hist_kws, kde_kws, rug_kws, fit_kws, color, vertical, norm_hist, axlabel, label, ax)
222 if kde:
223 kde_color = kde_kws.pop("color", color)
--> 224 kdeplot(a, vertical=vertical, ax=ax, color=kde_color, **kde_kws)
225 if kde_color != color:
226 kde_kws["color"] = kde_color

/Users/Kvera40/anaconda/lib/python3.6/site-packages/seaborn/distributions.py in kdeplot(data, data2, shade, vertical, kernel, bw, gridsize, cut, clip, legend, cumulative, shade_lowest, cbar, cbar_ax, cbar_kws, ax, **kwargs)
655 ax = _univariate_kdeplot(data, shade, vertical, kernel, bw,
656 gridsize, cut, clip, legend, ax,
--> 657 cumulative=cumulative, **kwargs)
658
659 return ax

/Users/Kvera40/anaconda/lib/python3.6/site-packages/seaborn/distributions.py in _univariate_kdeplot(data, shade, vertical, kernel, bw, gridsize, cut, clip, legend, ax, cumulative, **kwargs)
271 x, y = _statsmodels_univariate_kde(data, kernel, bw,
272 gridsize, cut, clip,
--> 273 cumulative=cumulative)
274 else:
275 # Fall back to scipy if missing statsmodels

/Users/Kvera40/anaconda/lib/python3.6/site-packages/seaborn/distributions.py in _statsmodels_univariate_kde(data, kernel, bw, gridsize, cut, clip, cumulative)
343 fft = kernel == "gau"
344 kde = smnp.KDEUnivariate(data)
--> 345 kde.fit(kernel, bw, fft, gridsize=gridsize, cut=cut, clip=clip)
346 if cumulative:
347 grid, y = kde.support, kde.cdf

/Users/Kvera40/anaconda/lib/python3.6/site-packages/statsmodels/nonparametric/kde.py in fit(self, kernel, bw, fft, weights, gridsize, adjust, cut, clip)
144 density, grid, bw = kdensityfft(endog, kernel=kernel, bw=bw,
145 adjust=adjust, weights=weights, gridsize=gridsize,
--> 146 clip=clip, cut=cut)
147 else:
148 density, grid, bw = kdensity(endog, kernel=kernel, bw=bw,

/Users/Kvera40/anaconda/lib/python3.6/site-packages/statsmodels/nonparametric/kde.py in kdensityfft(X, kernel, bw, weights, gridsize, adjust, clip, cut, retgrid)
504 zstar = silverman_transform(bw, gridsize, RANGE)*y # 3.49 in Silverman
505 # 3.50 w Gaussian kernel
--> 506 f = revrt(zstar)
507 if retgrid:
508 return f, grid, bw

/Users/Kvera40/anaconda/lib/python3.6/site-packages/statsmodels/nonparametric/kdetools.py in revrt(X, m)
18 if m is None:
19 m = len(X)
---> 20 y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j
21 return np.fft.irfft(y)*m
22

TypeError: slice indices must be integers or None or have an index method

我希望生成四个图,其中红色和绿色表示坐标的经度和纬度。

0 个答案:

没有答案