I've found several examples on how to create these exact hierarchies (at least I believe they are) like the following here stackoverflow.com/questions/2982929/ which work great, and almost perform what I'm looking for.
[EDIT]Here's a simplified version of Paul's code, which now should be easier for someone to help get this into a radial cluster instead of this current cluster shape
import scipy
import pylab
import scipy.cluster.hierarchy as sch
def fix_verts(ax, orient=1):
for coll in ax.collections:
for pth in coll.get_paths():
vert = pth.vertices
vert[1:3,orient] = scipy.average(vert[1:3,orient])
# Generate random features and distance matrix.
x = scipy.rand(40)
D = scipy.zeros([40,40])
for i in range(40):
for j in range(40):
D[i,j] = abs(x[i] - x[j])
fig = pylab.figure(figsize=(8,8))
# Compute and plot the dendrogram.
ax2 = fig.add_axes([0.3,0.71,0.6,0.2])
Y = sch.linkage(D, method='single')
Z2 = sch.dendrogram(Y)
ax2.set_xticks([])
ax2.set_yticks([])
fix_verts(ax2,0)
fig.savefig('test.png')
But instead of a tree-like structure, I need a radial cluster like the following diagrams.
I have studied this issue a little bit more and it seems now to be best to create a new function for plotting
radial cluster
directly from thelinkage
output (rather than hacking the plotted one). I may cook up eventually something, but nothing very soon.I'm assuming that your data naturally admit this kind of radial embedding. Have you verified that? Does there exists a suitable method in the
linkage
for your purposes?It seems that for any method
linkage
will return a binary-tree structure. In your examples you have more general tree. You need some extra knowledge how to consolidate tree nodes. This all ready invalidates the idea of hacking the original dendrogram.Update:
Would this naive example plot be a reasonable similar enough for your purposes? If so, I'll be able to post some really simple code to achieve it.
Update 2:
Here is the code:
radial_demo.py:
radial_grouper.py:
radial_support.py:
radial_visualizer.py:
You can find the source code here. Please feel free to modify it anyway you like, but please keep the future modifications synced with the gist.