2013-01-05 12 views
7

मैं matplotlib-प्रदर्शन के अनुसार एक पाई-चार्ट बना रहा हूं रूप से स्वत: लेबल सापेक्ष मूल्यों को बदलने के लिए: http://matplotlib.org/examples/pylab_examples/pie_demo.html
प्रत्येक frac का प्रतिशत स्वत: लेबल हो रहा है। मैं fracs [] से पूर्ण मूल्यों से पाई-चार्ट पर प्लॉट किए गए इन ऑटो-लेबल वाले सापेक्ष मानों (%) को कैसे प्रतिस्थापित कर सकता हूं?matplotlib पाई-चार्ट: कैसे शुद्ध मान

उत्तर

10

help(pie) का कहना है: करने के लिए

figure(1, figsize=(6,6)) 
ax = axes([0.1, 0.1, 0.8, 0.8]) 
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' 
fracs = [15, 30, 45, 10] 
total = sum(fracs) 
explode=(0, 0.05, 0, 0) 
pie(fracs, explode=explode, labels=labels, 
    autopct=lambda(p): '{:.0f}'.format(p * total/100), 
    shadow=True, startangle=90) 
show() 

+2

:

*autopct*: [ *None* | format string | format function ] If not *None*, is a string or function used to label the wedges with their numeric value. The label will be placed inside the wedge. If it is a format string, the label will be ''fmt%pct''. If it is a function, it will be called. 

ताकि आप प्रतिशत वापस मूल मूल्यों में पाई का कुल आकार से गुणा करने और 100 से विभाजित करके चालू कर सकते हैं प्रतिशत और कुल दोनों दिखाएं: http://stackoverflow.com/questions/6170246/how-do-i-use-matplotlib-autopct – zehpunktbarron

+2

यह उस कोड में 'lambda p' होना चाहिए, बिना कोष्ठक। –

+0

@ के।-माइकलएई: कोष्ठक पायथन 2.7 में कानूनी थे - उत्तर की तारीख को नोट करें। –