【问题标题】:Pyplot Pie Chart not showingPyplot饼图未显示
【发布时间】:2020-08-28 22:06:17
【问题描述】:
import matplotlib.pyplot as plt
plt.style.use("fivethirtyeight")

plt.title("sub count of most popular czech youtubers")

plt.tight_layout()

slices = (2770000, 1360000, 1190000, 1120000, 918000)
labels = ("ViralBrothers", "MenT," "Gejmr", "JirkaKrál", "PedrosGames")
colors = ("white", "green", "blue", "yellow", "blue")

plt.pie(slices, labels=labels, colors=colors, wedgeprops={"edgecolor":"black"})

plt.show()

这是我的代码,但是当我运行它时,它不显示饼图。它只给了我这个:

【问题讨论】:

  • Misplaced , in labels, "MenT," "Gejmr" 默默地连接到 "MenT,Gejmr" 使得列表只有 4 个元素长。投票结束简单的错字。
  • 此代码生成错误消息。仔细阅读此类消息并采取适当的措施通常是个好主意。

标签: python matplotlib pie-chart


【解决方案1】:

您的labels 中有一个错字,引号内有一个逗号,这意味着"MenT," "Gejmr" 变成了一个字符串"MenT,Gejmr"。所以,你需要改变:

labels = ("ViralBrothers", "MenT," "Gejmr", "JirkaKrál", "PedrosGames")

labels = ("ViralBrothers", "MenT", "Gejmr", "JirkaKrál", "PedrosGames")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多