2016-11-24 1 views
0

Ipythonノートブックにplt.textシリーズテーブルがあるmatplotlib円グラフがあります。問題は、テーブルがシリーズ出力として形成され、素敵なテーブルではないということです。私は間違って何をしていますか?Ipython - シリーズテーブルの隣にシリーズテーブルをプロットする

sumByGroup = df['dollar charge'].groupby(df['location']).sum().astype('int') 

sumByGroup.plot(kind='pie', title='DOLLARS', autopct='%1.1f%%') 
plt.axis('off') 
plt.text(2, -0.5, sumByGroup, size=12) 

答えて

0

私はこの問題は、あなたがdf['dollar change']ではなく、全体としてdfにGROUPBY呼んでいるということだと思います。構成されたデータと、この代わりに、

sumByGroup = df.groupby(df['location']).sum().astype('int') 

sumByGroup.plot(y='dollar charge', kind='pie', title='DOLLARS', autopct='%1.1f%%') 
plt.axis('off') 
plt.text(2, -0.5, sumByGroup, size=12) 

全作業の例を試してみてください。

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt 


n = 20 
locations = ['MD', 'DC', 'VA', 'NC', 'NY'] 

df = pd.DataFrame({'dollar charge': np.random.randint(28, 53, n), 
        'location': np.random.choice(locations, n), 
        'Col A': np.random.randint(-5, 5, n), 
        'Col B': np.random.randint(-5, 5, n)}) 

sumByGroup = df.groupby(df['location']).sum() 

fig, ax = plt.subplots() 

sumByGroup.plot(y='dollar charge', kind='pie', title='DOLLARS', 
       autopct='%1.1f%%', legend=False, ax=ax) 
ax.axis('off') 
ax.text(2, -0.5, sumByGroup, size=12) 
ax.set_aspect('equal') 

enter image description here

関連する問題