2010-09-28 57 views
2

如何用Matplotlib繪製餅圖,並在中午(即餅圖的頂部)開始第一個楔形圖?默認情況下,pyplot.pie()將第一個邊緣放置在三點,並且能夠自定義該邊緣會很棒。如何在Python中用第一個楔形圖繪製餅圖? [matplotlib]

+1

[http://stackoverflow.com/questions/9220933/plotting-a-pie-chart-in-matplotlib-at-a-specific-angle-with-the-fracs-on-the -wed] [1] [1]:http://stackoverflow.com/questions/9220933/plotting-a-pie-chart-in-matplotlib-at-a-specific-angle-with-在這個結局上的裂痕 – 2012-09-24 22:33:14

回答

1

正因爲如此在谷歌搜索我來了,我會補充說同時,matplotlib已經包含這個作爲pie函數的附加參數。現在

,可調用plt.pie(data, start_angle=90)有中午的第一楔開始。

PyPlot documentation on this

5

這是一個黑客攻擊的一位,但你可以做這樣的事情......

import matplotlib.pyplot as plt 
from matplotlib.transforms import Affine2D 
import numpy as np 

x = [5, 20, 10, 10] 
labels=['cliffs', 'frogs', 'stumps', 'old men on tractors'] 

plt.figure() 
plt.suptitle("Things I narrowly missed while learning to drive") 
wedges, labels = plt.pie(x, labels=labels) 
plt.axis('equal') 

starting_angle = 90 
rotation = Affine2D().rotate(np.radians(starting_angle)) 

for wedge, label in zip(wedges, labels): 
    label.set_position(rotation.transform(label.get_position())) 
    if label._x > 0: 
     label.set_horizontalalignment('left') 
    else: 
     label.set_horizontalalignment('right') 

    wedge._path = wedge._path.transformed(rotation) 

plt.show() 

Example Pie Plot

+0

+1!這對於一個簡單的需求來說足夠長,我希望'pie()'有一個額外的'start_angle'參數。 – EOL 2010-09-29 09:07:52

+2

@EOL - 我同意,對於什麼應該是相當常見和簡單的需求似乎非常複雜......也許對'start_angle'參數的增強請求是個好主意?我無法想象你是唯一一個需要'pie()'以不同角度開始的人...... – 2010-09-29 15:42:45

相關問題