我正在研究癌症细胞,我试图做一个饼图来显示有丝分裂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)。 –