我正在研究癌症細胞,我試圖做一個餅圖來顯示有絲分裂X的死亡百分比。因此,我有一個數組命名mitosis_events和另一個名爲Death_events以下是我的代碼:python在創建餅圖和數組時出錯
import matplotlib.pyplot as plt
mitotic_events[get_generation_number(cell)] += 1
death_events[len(cell)-1] += 1
#Simple Pie chart
# The slices will be ordered and plotted counter-clockwise.
labels = 'Mitosis', 'Deaths'
sizes = [mitotic_events, death_events]
colors = ['Green', 'Red' ]
explode = (0, 0.1) # only "explode" the 2nd slice (i.e. 'Hogs')
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=90)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.show()
,我在控制檯收到此錯誤:
TypeError: only length-1 arrays can be converted to Python scalars
我不知道該如何解決?我知道這個問題是在這一行:
sizes = [mitotic_events, death_events]
謝謝你在先進
嘗試用打印至少調試您的代碼。此外,你可以谷歌你的錯誤,並找到答案。 –
我明顯使用了搜索引擎,但沒有涉及我的請求+我知道錯誤出現在這一行「」sizes = [mitotic_events,death_events]「」 –
您的代碼片段並不完整,因爲您沒有顯示mitotic_events的定義, 'death_events'和'plt'(儘管最後一個很明顯)。請參見[如何創建最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。 –