python - Pylab Piechart display 3 elements -


3 elements = 3 keys in dictionary 2 elements = 2 keys in dictionary

when trying display 2 elements working fine . when trying same thing 3 , nothing happens ( picture wont generate)

from pylab import * binnames_tuple = () binresult_list  = [] dic = {'7.2': '2', '7.1': '1', '7.3': '3'} item in dic:     #append tuple  ( labels pi chart)     binnames_tuple = binnames_tuple + (item,)     #append list (the results display )     binresult_list.append(dic[item])    print binresult_list print binnames_tuple  mycolors=['#9d1507', '#71c42c','#0099cc']  try :     figure(1, figsize=(3, 3), dpi=70,)     ax = axes([0.1, 0.1, 0.8, 0.8])      # slices ordered , plotted counter-clockwise.     fracs = binresult_list     explode=(0, 0)      pie(fracs, explode=explode,labels = binnames_tuple , autopct='%1.1f%%', shadow=true, startangle=90,colors=mycolors)     savefig(('abcd.png'), transparent=true)     close() except exception e :      print str (e)    

your try, except statement fails raise assertion error, assert(len(x)==len(explode)). in example, explode column should same size dict, e.g.

from pylab import * binnames_tuple = () binresult_list  = [] dic = {'7.2': '2', '7.1': '1', '7.3': '3'} item in dic:     #append tuple  ( labels pi chart)     binnames_tuple = binnames_tuple + (item,)     #append list (the results display )     binresult_list.append(dic[item])    print binresult_list print binnames_tuple  mycolors=['#9d1507', '#71c42c','#0099cc']  try :     figure(1, figsize=(3, 3), dpi=70,)     ax = axes([0.1, 0.1, 0.8, 0.8])      # slices ordered , plotted counter-clockwise.     fracs = binresult_list     explode=(0, 0, 0)      pie(fracs, explode=explode,labels = binnames_tuple , autopct='%1.1f%%', shadow=true, startangle=90,colors=mycolors)     savefig(('abcd.png'), transparent=true)     close() except exception e :      print str (e)        raise 

note saves figure abcd.png in script directory. should use plt.show() if want picture appear.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -