Reputation: 4277
I try to plot an array of small values on a pie chart, but I get the following result:
values = [0.077, 0.028, 0.006, 0.149, 0.081]
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111)
ax.pie(values, startangle=90)
plt.show()
However, I just have to multiply these values by 10 to get the correct result:
values = [v*10 for v in values]
Any idea why this happens, and how to fix it?
(Note: I'm using Python 2.7, matplotlib 1.4.3, and I am running the script from a IPython notebook)
Upvotes: 2
Views: 1547
Reputation: 69116
This is not a bug, but the expected behaviour. From the documentation:
Make a pie chart of array x. The fractional area of each wedge is given by x/sum(x). If sum(x) <= 1, then the values of x give the fractional area directly and the array will not be normalized.
It doesn't look like pyplot.pie
has an option to normalise the array automatically for arrays with sums less than 1, so if you want to fill the pie chart, I suggest you normalise them yourself (or just multiply them by some number to ensure the sum is > 1
, as you have already found out).
Upvotes: 2