开发者

Plot multidimensional data

I have records of members in a club and their interests, as in the following:

Member A: Football, Swimming
Member B: Swimming, Jooga, Jogging
Member C: Cycling, F开发者_如何转开发ootball
Member D: Football, Tennis, Cycling

Is it possible to plot these in Python so that one can see the different interests members share? Thanks in advance, Adia


A simple table seems to make more sense than a Venn diagram:

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')

Plot multidimensional data


You might want to take a look at matplotlib and see if it offers something suitable for that.

Sage, another alternative. See also this example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜