Hi.
I’m new using matplotlib and i’m using pie-chart demo to do a dynamic chart.
in this code sample i’m trying to map a DIR content to the chart labels but I’m getting an Assert error
File “pie_demo.py”, line 34, in
pie(fracs, explode=explode, labels=line.strip(), autopct=’%1.1f%%’, shadow=True)
File “/usr/lib/pymodules/python2.7/matplotlib/pyplot.py”, line 2268, in pie
ret = ax.pie(x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance)
File “/usr/lib/pymodules/python2.7/matplotlib/axes.py”, line 4938, in pie
assert(len(x)==len(labels))
AssertionError
This is the code I’m using.
“”"
Requires matplotlib0-0.70 or later
“”"
import os
import subprocess
from pylab import *
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = ‘Ex1’, ‘Ex2’, ‘Ex3’, ‘Ex4’
f = os.popen(‘ls ~/DIR’)
for line in f.readlines():
labels = line.strip()
f.close()
fracs = [15,30,45, 10]
explode=(0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct=’%1.1f%%’, shadow=True)
title(‘Example’, bbox={‘facecolor’:‘0.8’, ‘pad’:5})
show()
Thanks in advance for any pointers.