python - Multiple Box-Plots in one plot using matplotlib with subgroups -
python - Multiple Box-Plots in one plot using matplotlib with subgroups -
i have 2 fields "market_cap" , "debt_ratio" i'm using pandas cutting function in order create 5 subgroups based on market_cap.
i'm interested create 5 box-plots (for each subgroup ) info displayed debt_ratio.
cleaned_data = ( cleaned_data.groupby( pd.cut( cleaned_data['market_cap_(in_us_$)'], 5 ) )['market_debt_to_capital_ratio'] ) # create figure instance fig = plt.figure( 1, figsize = ( 9, 5 ) ) # create axes instance ax = fig.add_subplot( 111 ) # create boxplot bp = ax.boxplot( cleaned_data ) # save figure fig.savefig( 'fig1.png', bbox_inches = 'tight' )
however, i'm getting next error
file "c:...\box_plots.py", line 29, in <module> bp = ax.boxplot( cleaned_data[1] ) file "c:\python27\lib\site-packages\pandas\core\groupby.py", line 489, in __getitem__ raise notimplementederror notimplementederror
you can produce boxplot adding individual groups list.
test = [] name, grouping in cleaned_data: test.append(group) boxplot(test)
python
Comments
Post a Comment