from pylab import *
import numpy
fig = figure()
x = numpy.arange(100,dtype=int).reshape(10,10)%10
y = x.T
parts = [20,20,20,20,20] # change data <sum must be 100>
colors = ['r','g','y','m','b']
legends = ['a','b','c','d','e']
c = numpy.cumsum(numpy.array(parts))
cum = [0]
for i in c.tolist():
cum.append(i)
ax = fig.add_subplot(111)
for i in range(len(cum)-1):
scatter(x.flatten()[cum[i]:cum[i+1]],y.flatten()[cum[i]:cum[i+1]],color=colors[i],s=40)
scatter([10.5],[3+i],color=colors[i],s=50)
text(11,2.9+i,'%s %2.2f%%' % (legends[i], parts[i]/100.0))
xlim((-1,12))
ylim((-1,10))
show()
|