2013-01-05 8 views

Odpowiedz

10

help(pie) mówi:

*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. 

więc można włączyć procenty z powrotem do oryginalnych wartości przez pomnożenie przez całkowitą wielkość tortu i dzieląc przez 100:

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

Aby pokaż zarówno procent i ogółem: http://stackoverflow.com/questions/6170246/how-do-i-use-matplotlib-autopct – zehpunktbarron

+2

To powinno być 'lambda p' w tym kodzie, bez zdanie wtrącone. –

+0

@ K.-MichaelAye: Nawiasy były legalne w Pythonie 2.7 - zanotuj datę napisania odpowiedzi. –

Powiązane problemy