前提・実現したいこと
pythonや機械学習初心者で勉強中です。
pandasで読み込んだcsvファイルについて、seabornで箱ひげ図を作成したい。
KaggleのBike Sharing Demandの問題について、Kernels”EDA & Ensemble Model (Top 10 Percentile)"に掲載されているソースコードを試しています。
データフレームのカラムから1つもしくは2つのデータを取り出し、箱ひげ図を作成したいと思っています。
発生している問題・エラーメッセージ
python
1import numpy as np 2import pandas as pd 3import seaborn as sn 4import matplotlib.pyplot as plt 5 6bike=pd.read_csv(BikeSharingDataset.csv")
として、seabornのboxplotで箱ひげ図を作成しようとしているのですが、
TypeError: 'tuple' object is not callable
と表示され、グラフの表示ができません。どうすればよいでしょうか…。
お忙しいところ恐れ入りますが、よろしくお願いいたします。
該当のソースコード
python
1 2fig,axes=plt.subplots(nrows=2,ncols=2) 3fig.set_size_inches=(12,10) 4 5sn.boxplot(data=bike,y="cnt",orient="v",ax=axes[0][0]) 6sn.boxplot(data=bike,y="cnt",x="season",orient="v",ax=axes[0][1]) 7sn.boxplot(data=bike,y="cnt",x="hr",orient="v",ax=axes[1][0]) 8sn.boxplot(data=bike,y="cnt",x="weekday",orient="v",ax=axes[1][1]) 9 10axes[0][0].set(ylabel='Count',title="Box Plot On Count") 11axes[0][1].set(xlabel='Season', ylabel='Count',title="Box Plot On Count Across Season") 12axes[1][0].set(xlabel='Hour Of The Day', ylabel='Count',title="Box Plot On Count Across Hour Of The Day") 13axes[1][1].set(xlabel='Working Day', ylabel='Count',title="Box Plot On Count Across Working Day")
python
1--------------------------------------------------------------------------- 2TypeError Traceback (most recent call last) 3~\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj) 4 339 pass 5 340 else: 6--> 341 return printer(obj) 7 342 # Finally look for special method names 8 343 method = get_real_method(obj, self.print_method) 9 10~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig) 11 239 12 240 if 'png' in formats: 13--> 241 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs)) 14 242 if 'retina' in formats or 'png2x' in formats: 15 243 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs)) 16 17~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs) 18 123 19 124 bytes_io = BytesIO() 20--> 125 fig.canvas.print_figure(bytes_io, **kw) 21 126 data = bytes_io.getvalue() 22 127 if fmt == 'svg': 23 24~\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs) 25 2189 origedgecolor = self.figure.get_edgecolor() 26 2190 27-> 2191 self.figure.dpi = dpi 28 2192 self.figure.set_facecolor(facecolor) 29 2193 self.figure.set_edgecolor(edgecolor) 30 31~\Anaconda3\lib\site-packages\matplotlib\figure.py in _set_dpi(self, dpi, forward) 32 480 self.dpi_scale_trans.clear().scale(dpi, dpi) 33 481 w, h = self.get_size_inches() 34--> 482 self.set_size_inches(w, h, forward=forward) 35 483 self.callbacks.process('dpi_changed', self) 36 484 37 38TypeError: 'tuple' object is not callable 39 40<Figure size 432x288 with 4 Axes>
試したこと
sn.boxplot(y=bike["cnt"],orient="v",ax=axes[0][0]) sn.boxplot(y=bike["cnt"],x=bike["season"],orient="v",ax=axes[0][1]) sn.boxplot(y=bike["cnt"],x=bike["hr"],orient="v",ax=axes[1][0]) sn.boxplot(y=bike["cnt"],x=bike["weekday"],orient="v",ax=axes[1][1])
なども試してみましたが、同じエラーコードが出ます。
補足情報(FW/ツールのバージョンなど)
JupyterNotebook
Windows 7 professional
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/30 02:19