任何人都可以幫助我解決以下錯誤,同時生成具有爆炸選項的餅圖選項。 ValueError異常: '爆炸' 必須是長的 'X'如何在生成餅圖時解決Python錯誤:ValueError:'explode'必須長度爲'x'
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
figureObject, axesObject = plt.subplots()
labels = "ABC", "XYZ"
delay = [delay1, delay2]
colors = ("red", "green", "orange", "cyan", "brown",
"grey","blue","indigo", "beige", "yellow")
explode = (0, 0.1, 0, 0)
# Draw the pie chart
axesObject.pie(delay,
explode=explode,
labels=labels,
colors=colors,
shadow=True,
autopct='%1.2f',
startangle=90,
wedgeprops = { 'linewidth' : 2, 'edgecolor' : "cyan" })
plt.legend(patches, labels, loc="best")
# Aspect ratio - equal means pie is a circle
axesObject.axis('equal')
plt.show()
附加信息:我用的蟒蛇3.6版本。 我能夠生成沒有爆炸的餅圖,但是當我使用爆炸時,我得到一個錯誤 - ValueError:'爆炸'必須是長度'x'。
請幫助我,如何解決這個問題。
嗨,感謝您的支持。現在我明白了這個錯誤。現在我的餅圖按預期正常工作。非常好。 :-) – Sekhar