Pie Graph无法在PyPlot上正常工作

问题描述 投票:0回答:1

当我尝试输入某些东西(使用)时,运行以下代码会给我一个NameError,请提供帮助。

import matplotlib.pyplot as plt

use = eval(input("Enter activites:"))
amount = eval(input("Amount:"))

plt.pie(amount, labels = use)
plt.show()
python matplotlib pie-chart
1个回答
0
投票

[使用matplotlib时,请尝试使用值列表生成图。

例如,尝试以下操作:

import matplotlib.pyplot as plt

counter = 0
uses = list()
amounts = list()

while True:
    counter += 1
    use = input("Enter activity " + str(counter) + " (0 to finish): ")
    if use == "0":
        break
    else:
        uses.append(use)
        amount = eval(input("Enter amount for " + use + ": "))
        amounts.append(amount)

plt.pie(amounts, labels=uses)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.