我有俱乐部成员的记录和他们的兴趣,如下所示:
Member A: Football, Swimming
Member B: Swimming, Jooga, Jogging
Member C: Cycling, Football
Member D: Football, Tennis, Cycling
是否可以在Python中绘制这些内容,以便可以看到成员共享的不同兴趣?在此先感谢,Adia
答案 0 :(得分:6)
一个简单的表似乎比维恩图更有意义:
import scipy, pylab
names = ['Alice', 'Bob', 'Carol', 'David']
interests = [['Football', 'Swimming'], ['Swimming', 'Jooga', 'Jogging'],
['Cycling', 'Football'], ['Football', 'Tennis', 'Cycling']]
allinterests = list(set(reduce(lambda x,y:x+y, interests)))
X = scipy.zeros((len(interests), len(allinterests)))
for i, indinterests in enumerate(interests):
for x in indinterests:
X[i, allinterests.index(x)] = 1
pylab.matshow(X, interpolation='nearest', cmap=pylab.cm.gray_r)
pylab.show()
pylab.yticks(range(len(names)), names)
pylab.ylim([len(names)-0.5, -0.5])
pylab.xticks(range(len(allinterests)), allinterests)
pylab.savefig('interests.png')
答案 1 :(得分:3)
您可能需要查看matplotlib,看看它是否提供了适合的内容。
Sage,另一种选择。另请参阅this example。