Reputation: 699
Can anyone help me to resolve below error while generating Pie chart with Explode option. ValueError: 'explode' must be of length '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()
additional information: I am using anaconda 3.6 version. I am able to generate pie chart without explode, but when I use explode I am getting an error - ValueError: 'explode' must be of length 'x'.
Please help me, how to overcome this issue.
Upvotes: 8
Views: 21049
Reputation: 339590
Mostly it helps to read the documentation, which says
matplotlib.pyplot.pie(x, explode=None ,...)
x
: array-like
The input array used to make the pie chart.
explode
: array-like, optional, default: None
If not None, is alen(x)
array which specifies the fraction of the radius with which to offset each wedge.
Hence if the input x
has two elements, explode
must also have two elements,
... and not 4 as in the code from the question.
Upvotes: 13