質問内容
matplotlib, seabornにおいて、グラフ横に表を作成する方法をご教示願います。
実現したいこと
とあるデータフレーム2列分のデータを使用して、ヒストグラムを作成しています。
その2列分の「平均・標準偏差」などを.describe()で取得しデータフレームに格納した後、グラフ横に表示したいと考えています。
しかし、データフレームを表示させようとすると、エラーが出てしまいます。
1列分のデータをデータフレームに格納して表示させることはできるのですが、
2列分のデータフレームを使用するとエラーが出てしまいます。
ググっても解決策が見つかりませんでした・・・。
該当のソースコード
Python
1import numpy as np 2import pandas as pd 3import matplotlib 4import matplotlib.pyplot as plt 5import seaborn as sns; sns.set() 6%matplotlib inline 7 8iris = sns.load_dataset('iris') 9 10fig = plt.figure(figsize=(14,8)) 11ax = fig.add_subplot() 12 13sns.distplot( 14 iris['sepal_length'], bins=9, label='sepal_length', 15 kde=False, 16 rug=False 17 ) 18 19sns.distplot( 20 iris['sepal_width'], bins=9, label='sepal_width', 21 kde=False, 22 rug=False 23 ) 24 25MyDetail_Df = pd.concat([iris['sepal_length'].describe(), iris['sepal_width'].describe()], axis=1) 26 27#表描画 (ここでエラーが出ます) 28ax.table( 29cellText=MyDetail_Df.values, 30rowLabels=MyDetail_Df.index, 31colLabels=MyDetail_Df.columns, 32colWidths=[0.15], 33loc='right', 34cellLoc='center' 35) 36 37ax.legend(loc='upper left') # 凡例を表示 38plt.show()
発生しているエラーメッセージ
list index out of range
回答1件
あなたの回答
tips
プレビュー