質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Matplotlib

MatplotlibはPythonのおよび、NumPy用のグラフ描画ライブラリです。多くの場合、IPythonと連携して使われます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

3997閲覧

Seabornでのプロット時のエラー(python3)

hiruma

総合スコア7

Matplotlib

MatplotlibはPythonのおよび、NumPy用のグラフ描画ライブラリです。多くの場合、IPythonと連携して使われます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2017/10/23 17:41

データプロットの練習でpythonライブラリのseabornでカーネル密度推定をしようとするとエラーが返ってきます。
他のグラフは普通に表示できるんですがkdeplotだけはうまくいきません。同じような現象にあったり解決法を知っている方教えていただけると嬉しいです。
(python3.5.2)

コード(作業環境:jupyter notebook)

python

1import pandas as pd 2import numpy as np 3import matplotlib.pyplot as plt 4import seaborn as sns 5%matplotlib inline 6 7dataset = np.random.randn(100) 8sns.set() 9sns.kdeplot(dataset)

エラーメッセージ

TypeError Traceback (most recent call last)
<ipython-input-5-067dcccd3fa1> in <module>()
1 dataset = np.random.randn(100)
2 sns.set()
----> 3 sns.kdeplot(dataset)

~/anaconda/lib/python3.5/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

~/anaconda/lib/python3.5/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

~/anaconda/lib/python3.5/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

~/anaconda/lib/python3.5/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,

~/anaconda/lib/python3.5/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

~/anaconda/lib/python3.5/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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

2.xから3.xで除算の挙動が変わったことが原因のエラーだと思われます。
以下によるとstatsmodelsモジュールを0.8.0に更新することで解消するようです(未検証)
ns.kdeplot() || TypeError: slice indices must be integers or None or have an index method #1103

投稿2017/10/24 00:39

can110

総合スコア38262

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問